Technology Sharing

5 Better ways to code in Rust

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

This article is a tribute to the well-known Rust video bloggerLet's Get Rustyof5 Better ways to code in RustThis video was translated and edited, and some content was modified to fit the Chinese idiom. The copyright belongs to the original author.


Hello everyone, I'm going to show you 5 ways to improve your Rust coding experience. Whether you're a complete beginner or an experienced Rust developer, these tips will be valuable to you. At the end of the video, I'll also share a sixth bonus tip that's quite controversial, so make sure to stick around until the end.

OK, let's get started.


Perfect IDE setup


Assuming you have Rust installed, the next thing you want to do is make sure your IDE is set up correctly. VS Code is my top choice because it's easy to use, available for all major operating systems, and highly configurable. To configure VS Code for Rust development, there are three must-have extensions and some optional but very powerful extensions that I highly recommend.

Here are three must-have extensions:

  1. Rust Analyzer: Rust's official language server, providing code completion, jump to definition, inline hints and other functions.
  2. CodeLLDB: This extension allows you to debug Rust code.
  3. Better TOML: Provides syntax highlighting for TOML files.

With these three extensions, you can start Rust development. In addition, there are some very powerful optional extensions that are also worth installing:

  1. Error Lens: Improves error and warning highlighting. As you can see, it makes errors stand out more and displays error messages inline.
  2. Todo Tree: Helps you quickly find todo items in your code. A cool feature of Todo Tree is that it uses a regular expression to match todo items, and you can change this regular expression. In this example, I changed the regular expression so that it also highlights the todo! macro.