Andy Crouch - Code, Technology & Obfuscation ...

Debugging Rust

Photo: Unsplash - David Boca

Lately, I have been reading up and learning the Rust programming language. This was caused by me taking on some JavaScript backend projects and thinking “there has to be a better way”. Don’t go hating on me yet JavaScript developers, wait for the post on my JavaScript thoughts. Stay tuned.

Rust has been around for over ten years and is a multi-paradigm language developed at Mozilla. Its primary focus is memory safety and concurrency and syntax that should be familiar to anyone that has worked with the C family of languages. I have read the odd thing about Rust over the years but what made me take notice was finding techempower.com and learning about the Actix Web framework based on Rust. So I have been making an effort to learn more about the language and development workflow. I have a long way to go but have enjoyed getting familiar with Rust. I may even write a short series on it late in the year.

One of the first things that I do when learning a new language is set up a development environment and work out how to debug code. I use either Vim or VS Code and for Rust VS Code was ideal given I am time poor at the moment.

To get Rust setup I:

  • Followed the excellent instructions found at the Rust install page. This gives a good overview of rustup which is an equivalent to nvm or pyenv.

  • Installed the Rust(Rls) extension for VS Code. I did try the Rust Analyzer extension but there is a bug at present which means that the Vim keybindings no longer work.

  • Install the CodeLLDB extension which provides a native debugger.

  • Open your user settings and under the LLDB settings set the “Lldb: Executable” setting to rust-lldb.

  • With a Rust project open, hit F5 and VS Code will tell you it has found a Cargo.toml file in the workspace and then ask if you would like it to create a launch config. Say yes and set your breakpoints.

At this stage, you have a working development environment which will allow you to start learning more about Rust.

If you have recommended links on developing Rust then please share them with me via twitter or email.