Skip to content

Essential Crates

Development Tools

clippy

  • Linter and error checker that helps catch common Rust coding mistakes

rustfmt

  • Standard Rust formatter

tarpaulin

  • Testing and code coverage library

Async

tokio

  • Mature async runtime with large community

Error Handling

thiserror

  • Derive macro for custom error types. Use this in libraries to simplify the creation of custom error types and error handling.

Example

rust
use anyhow::Error as AnyhowError;
use config::ConfigError;
use fern::InitError;
use std::io::Error as IoError;
use std::net::AddrParseError;
use thiserror::Error as ThisError;

#[derive(ThisError, Debug)]
pub enum MyError {
    #[error("Failed to connect: {0}")]
    ConnectError(#[from] IoError),
    #[error("Malformed configuration: {0}")]
    ConfigurationError(#[from] ConfigError),
    #[error("Failed to parse into SocketAddr: {0}")]
    ParseError(#[from] AddrParseError),
    #[error("Encountered generic `anyhow` error: {0}")]
    GenericError(#[from] AnyhowError),
}

// Now type alias the Result
type Result<T> = std::result::Result<T, MyError>;
use anyhow::Error as AnyhowError;
use config::ConfigError;
use fern::InitError;
use std::io::Error as IoError;
use std::net::AddrParseError;
use thiserror::Error as ThisError;

#[derive(ThisError, Debug)]
pub enum MyError {
    #[error("Failed to connect: {0}")]
    ConnectError(#[from] IoError),
    #[error("Malformed configuration: {0}")]
    ConfigurationError(#[from] ConfigError),
    #[error("Failed to parse into SocketAddr: {0}")]
    ParseError(#[from] AddrParseError),
    #[error("Encountered generic `anyhow` error: {0}")]
    GenericError(#[from] AnyhowError),
}

// Now type alias the Result
type Result<T> = std::result::Result<T, MyError>;

anyhow

  • Easy idiomatic error type. Use this in binaries for a simple generic error type.

Messaging

rumqtt

  • Rust implementation of the MQTT standard

serde

  • Simple and fast serialization and deserialization

APIs

reqwest

  • Make and manage API calls in Rust.

Honourable Mentions

bacon: Background Rust error checker cargo-check: Checks for changes in code and runs commands when this occurs

RESOURCES