Posted on

Hot reloading, Test coverage and more

Welcome to the most recent release of the Rust Trends newsletter, where I present to you the most up-to-date news and insights from the dynamic Rust community. No matter if you’re an experienced Rust developer or a newcomer, there’s something in here for you. In this edition, we’ll explore topics like building your backend using Rust, the advantages of hot reloading, and how to achieve comprehensive test coverage.

Let’s dive into today’s topics and discover the latest and greatest in the world of Rust programming!

Building a Backend in Rust

Rust Backend

Are you curious about why you should build your backend in Rust? Not only is it fast, secure, and reliable, resources become more widely available. Rust’s unique combination of performance and safety features has made it a go-to choice for backend development. Rust is an excellent choice for building your backend.

But that is not all! If you want to make use of a serverless approach like AWS API Gateway, you can still benefit from writing the functions, called lambdas on AWS, in Rust. Check out this page on lambda performances (cold start, average memory used, and duration). A youtube video on the same topic from the same author can be found here.

And if you are still wondering why Rust is worth considering for your backend, we have got an opinion piece, from a credible source, that is sure to persuade you. It discusses the unique features of Rust that make it stand out from other programming languages and explains why Rust is quickly becoming a top choice for backend developers.

So, what are you waiting for? Click on those links and start exploring the power of Rust on the backend!

Hot reloading with cargo watch

Cargo Watch
If you are looking for a handy tool to automate the build and rebuild process in your Rust project directory, look no further than cargo-watch. This nifty tool automatically builds and rebuilds your Rust project when changes are saved, so you can focus on coding without worrying about manually rebuilding every time you make a change.

To install cargo-watch, simply run the following command:

$ cargo install cargo-watch

Make sure to include the path with the binaries (e.g., /Users/bob/.cargo/bin) in your $PATH variable, and you can execute it from anywhere on your CLI.

Here are some useful commands to use in a Rust project directory:

# Rebuilding on changes:
$ cargo watch
# Clearing the screen before each run:
$ cargo watch -c
# Monitor directory for changes:
$ cargo watch –watch src/ -x ‘run’

Check out the cargo-watch Github repository for more information and documentation. Happy coding!

Test coverage, to make sure we got you covered

Are you looking for a tool to help you test and ensure code coverage in your Rust project? Meet cargo tarpaulin! This handy tool provides coverage statistics and visualizations, allowing you to easily identify untested code and ensure comprehensive test coverage.

To install cargo tarpaulin, simply run the following command:

$ cargo install cargo-tarpaulin

Once installed, you can use the following command to generate a coverage report for your Rust project:

$ cargo tarpaulin –workspace

This command generates a coverage report for all the tests in your project, including integration tests.

You can also use the following command to customize the coverage report:

# Output a coverage report in different formats, such as HTML, JSON, or XML:
$ cargo tarpaulin –out Html –output-dir ./target/coverage

You can set coverage goals, e.g. –line 75, for your project and fail the build if the coverage is below 75%. Check out the cargo tarpaulin Github repository for more information and documentation. With cargo tarpaulin, you can ensure comprehensive test coverage and identify any untested code in your Rust project.

Testing

Snippets


Do not hesitate to explore new possibilities in Rust. Pushing yourself out of your comfort zone can be a great way to learn and grow as a programmer.

Thanks for reading!
Bob Peters

Feel free to connect with me on LinkedIn