Diving into Rust: A Fun Journey into Rust with the "template-rs" Project - Part 2

Hey there, fellow Rustaceans and coding enthusiasts! Today, we're diving into something really cool: the "template-rs" project. It's like the Swiss Army knife of Rust project templates – versatile and handy. Who likes writing boilerplate anyway? So, buckle up, grab your favorite snack (mine's chocolate-covered code snippets), and let's get started! Find the repository here

What's "template-rs" Anyway?

Imagine you're starting a new Rust project. You're excited, but also dreading the setup part. Enter "template-rs" – an opinionated, open-source Git repository template specifically for Rust projects. It's like having a wise old Rust guru guide you through the initial setup, ensuring you're on the path to best practices in continuous integration and code coverage. Ok, now it is more like a baby Guru, but it will grow in time, as I explore this language and hopefully find some good suggestions on the road!

Getting Started: The 'Fork-and-Clone' Boogie

First things first, you need to get your hands on this template. It's as simple as cloning or forking the repository. Or, if you want to start a new repository in Github, you can reference it as the template of the newly created repository. Got it? Great! Now, engage in the mystical art of the 'Replace All' dance, where you swap out "template-rs" with your project's name in all project files. Tools like Visual Studio Code are your dance partners here.

Tarpaulin: Your Code Coverage Crystal Ball

Tarpaulin is not a magical tarp for your code, but close enough. It's a Rust-specific tool that shows how much of your code is actually being tested. Setting it up is a breeze:

  1. Make sure Rust and Cargo are installed (like having flour and sugar for baking).
  2. Install Tarpaulin with cargo install cargo-tarpaulin.

To run it, just chant the incantation cargo tarpaulin, and voilà, you have a coverage report!

GitHub Actions: The Automation Wizards

GitHub Actions are like your code's personal team of wizards, automating workflows in your GitHub repository. In "template-rs", they're set to cast their spells whenever a new pull request is made, building and testing your codebase.

Workflow Potion Ingredients:

  1. Rust environment setup.
  2. Dependency caching (for speedy spellcasting).
  3. Project build.
  4. Running tests (to ensure your code's magic is strong).

Codecov: The Coverage Oracle

Codecov is like the oracle of your coding temple, visualizing code coverage and making sure every part of your code is tested, especially during pull requests.

Integrating Codecov:

  1. Sign up on Codecov, link your GitHub repo.
  2. Add the CODECOV_TOKEN as a secret in your GitHub settings.
  3. The .github/workflows/rust_build_and_test.yml file already includes a step to upload coverage reports to Codecov.

Wearing the Badge of Honor:

Want to show off your coverage prowess? Add a Codecov badge to your README by copying the Markdown code from your Codecov repo page.

Features:

  • Tarpaulin for Test Coverage: Ensuring our tests are actually testing.
  • GitHub Actions for CI: Automating our build and test processes.
  • Codecov Integration: Keeping an eye on our code coverage.

Coming soon:

  • Deployment, Docker, Quality Checks, Multi-Platform Testing, and more!

Side notes on documentation

One thing that I had to drop and took more time than I expected has been deploying documentation to Github Pages automatically.

Cargo doc creates a static web site which documents everything in your codebase automatically, based on your comments.

The workflow actually worked, but unfortunately, links appear to be broken when deploying to Github Pages. Will definitely give it a second try in the future!

Conclusions

So, if you've got suggestions, tips, or just want to talk about how cool Rust is (I mean, who doesn't?), feel free to reach out.🦀💻🚀

And remember, the journey of a thousand lines of code begins with a single cargo run. Happy coding!