Ferris the crab, unofficial mascot for Rust

Rust is a programming language released in 2015 that promises performance and reliability. I’ve been looking to build some side projects that I can let run for a long time with minimal monitoring, and it seems like Rust can deliver.

Since I am already familiar with a few other programming languages, the transition doesn’t feel too bad. I’m approaching this in terms of my ability to build features, and to that end, there are some key areas I like to focus on.

Data Modeling

Analyzing and structuring data is a basic capability required to execute any feature. We can accomplish this in Rust using structs and enums. Rust is also a statically typed language, which mandates understanding the underlying data types.

Structs and Enums for Order Data

Control Flow

Rust has the standard control flow structures that all other programming languages have, along with a few extra features. Note, there is an explicit return keyword available, but if you don’t want to use it, the last line automatically returns if we omit the semicolon. I found this similar to Ruby.

Functions, Conditionals and Loops

Organizing Code

In any non-trivial system, we will need to have separation of concerns and division of the codebase into multiple files. Rust has an opinionated module system that requires explicit declaration with the mod keyword, along with a specified directory structure when we need submodules.

Module structure

Unit Tests

I have worked with Go recently, and I love its straightforward testing flow. Rust also has a similar system that makes this quite easy. Unit tests go in the module file, and integration tests can be moved out to a separate directory.

Test module in orders.rs

Error Handling

Errors aren’t thrown but passed back using the Result enum. Additionally, we can create panics with trace.

Orders.rsRoutes.rs

Package Manager

As with any project, there are many dependencies that we need to take care of. Rust has a package manager called cargo, and it calls its packages crates. It’s quite easy to use: cargo add <package-name>. It stores all the crates in Cargo.toml and creates a lock file to manage downstream dependencies and crate versions.

Cargo.toml of a test webserver

Command Line Interface

Most new programming languages come with a host of support tools built into an accompanying CLI. Rust has cargo, which allows you to:

Add packages: cargo add <crate>Run tests: cargo testRun the build for testing: cargo runRun the build in watch mode: cargo watch -x runCreate the production build: cargo build — release

These are the commands I have worked with so far. The CLI is modular and extensible, allowing for additional capabilities by downloading crates that add to the CLI.

Watch, run and build cli commands

Ecosystem

Rust is a relatively new programming language, so many of the popular crates have not yet reached version 1. However, the quality of available crates is decent, and there is a lot of rapid development in progress. The community is vibrant, and everywhere I look, people are excited about what they are building. Crate registry: https://crates.io/

crates.io

There is a lot of momentum behind Rust. With backing from Mozilla and it being ranked the most admired language in the 2023 Stack Overflow survey, another of which is around the corner, I believe Rust will only rise in popularity in the future.

Experiments with Rust was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.

​ Level Up Coding – Medium

about Infinite Loop Digital

We support businesses by identifying requirements and helping clients integrate AI seamlessly into their operations.

Gartner
Gartner Digital Workplace Summit Generative Al

GenAI sessions:

  • 4 Use Cases for Generative AI and ChatGPT in the Digital Workplace
  • How the Power of Generative AI Will Transform Knowledge Management
  • The Perils and Promises of Microsoft 365 Copilot
  • How to Be the Generative AI Champion Your CIO and Organization Need
  • How to Shift Organizational Culture Today to Embrace Generative AI Tomorrow
  • Mitigate the Risks of Generative AI by Enhancing Your Information Governance
  • Cultivate Essential Skills for Collaborating With Artificial Intelligence
  • Ask the Expert: Microsoft 365 Copilot
  • Generative AI Across Digital Workplace Markets
10 – 11 June 2024

London, U.K.