rust
pub fn add(a: i32, b: i32) -> i32 {
    a + b
}

#[cfg(test)]
mod tests {

Unit tests with #[test] and assert macros

rust testing
by Marcus Chen 1 tab
toml
[features]
default = ["json"]
json = ["serde_json"]
yaml = ["serde_yaml"]

[dependencies]

Feature flags for conditional compilation

rust cargo features
by Marcus Chen 2 tabs
toml
[workspace]
members = [
    "server",
    "client",
    "common",
]

Cargo workspaces for multi-crate projects

rust cargo workspace
by Marcus Chen 1 tab
rust
use sqlx::PgPool;

#[derive(sqlx::FromRow)]
struct User {
    id: i32,
    name: String,

sqlx for compile-time checked SQL queries with async

rust database sql
by Marcus Chen 1 tab
rust
use axum::{Router, routing::get};
use tower::ServiceBuilder;
use tower_http::{trace::TraceLayer, timeout::TimeoutLayer};
use std::time::Duration;

async fn handler() -> &'static str {

Tower middleware for composable HTTP service layers

rust tower middleware
by Marcus Chen 1 tab
rust
use axum::{routing::get, Router, Json};
use serde::Serialize;

#[derive(Serialize)]
struct Response {
    message: String,

axum for type-safe async HTTP servers

rust async axum
by Marcus Chen 1 tab
rust
use reqwest;
use serde::Deserialize;

#[derive(Deserialize, Debug)]
struct Post {
    id: u32,

reqwest for async HTTP client with connection pooling

rust http async
by Marcus Chen 1 tab
rust
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug)]
struct Config {
    host: String,
    port: u16,

serde for zero-copy serialization and deserialization

rust serde serialization
by Marcus Chen 1 tab
rust
use clap::Parser;

#[derive(Parser, Debug)]
#[command(author, version, about)]
struct Args {
    #[arg(short, long)]

clap for CLI argument parsing with derive macros

rust cli clap
by Marcus Chen 1 tab
rust
use std::rc::Rc;
use std::cell::RefCell;

fn main() {
    let data = Rc::new(RefCell::new(vec![1, 2, 3]));

Rc and RefCell for shared ownership with interior mutability

rust smart-pointers interior-mutability
by Marcus Chen 1 tab
rust
enum List {
    Cons(i32, Box<List>),
    Nil,
}

use List::{Cons, Nil};

Box<T> for heap allocation and recursive types

rust smart-pointers heap
by Marcus Chen 1 tab
rust
enum Status {
    Ok,
    Error(String),
    Pending,
}

Pattern matching with match for exhaustive case handling

rust pattern-matching
by Marcus Chen 1 tab