Notes tagged with: rust

September 5, 2022

rust

Rust Analyzer from Source

I’m developing on a FreeBSD machine and rust-analyzer is not available as a pre-build release.

Luckily, it’s easy to build rust-analyzer from source. Just clone the repository and run:

cargo xtask install --server

I’m on Emacs, so I only need the server, hence the --server argument. If you are using Visual Studio Code, don’t add it.

April 14, 2022

rust

Cargo modules

Today I learned about the cargo-modules, a cargo plugin which shows you an overview of your crates modules.

I like to check the tree and my public interface with:

cargo modules generate tree --with-types

August 1, 2021

rust

Add aliases for your Rust project

I was looking at the Monkey language implementation done by Lauren Tan and noticed a .cargo/config.toml file in the project directory. In it was a convenient alias for her project:

dev = "watch -x check -x test"

This way, we can run cargo dev, which will run a check, which is not a build but catches a lot of errors quickly. The test is for those doing TDD because it will run the tests after every change. Convenient!

Rust project templates

Rust never stops to amaze me with its command-line tools and today I found out about cargo-generate which enables you to setup a repository which will function as a project template for Rust.

As an example, to pull down the repository and start a new project, you would do:

cargo generate --git https://github.com/githubusername/mytemplate.git --name myproject

Staying up-to-date with Rust

I have this tick where I continuously check that my tools are running the latest version. I guess you could call it a form of FOMO.

Luckily, Rust has me covered with two packages which check that for me.

cargo-outdated which check that your project dependenies are up-to-date. And cargo-update which checks that your Rust executables, like cargo-edit are running the latest version.

It will even update itself!

May 24, 2021

rust

Rust tooling came a long way

I bought the Hands-on Rust and needed to setup my editor (Visual Studio Code) to start working on my 2D dungeon crawler. Choose Rust Analyzer and could not be more impressed with the experience.

Also impressed with some of the Cargo helper tools, like cargo-edit to manage dependencies, cargo-audit to check for vulnerabilities and cargo-expand to expand macro’s.

2021 is a great year to start learning Rust. Both the ecosystem and learning materials have reached a high level of maturity.