rust

rust
struct Config<'a> {
    name: &'a str,
    value: &'a str,
}

fn parse_config(line: &str) -> Config {

Lifetime annotations for flexible borrowing in structs

rust lifetimes borrowing
by Marcus Chen 1 tab
rust
use crossbeam::channel::unbounded;
use std::thread;

fn main() {
    let (tx, rx) = unbounded();

Crossbeam for advanced concurrent data structures

rust concurrency lock-free
by Marcus Chen 1 tab
rust
use tracing::{info, instrument};

#[instrument]
fn process_request(user_id: u64) {
    info!(user_id, "Processing request");
    // Work happens here

tracing for structured logging and distributed tracing

rust observability tracing
by Marcus Chen 1 tab
rust
use std::sync::mpsc;
use std::thread;

fn main() {
    let (tx, rx) = mpsc::channel();

Channels (mpsc) for message passing between threads

rust concurrency channels
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
macro_rules! create_function {
    ($func_name:ident) => {
        fn $func_name() {
            println!("Called {}", stringify!($func_name));
        }
    };

Declarative macros (macro_rules!) for code generation

rust macros metaprogramming
by Marcus Chen 1 tab
rust
use my_crate::add;

#[test]
fn test_public_api() {
    assert_eq!(add(3, 4), 7);
}

Integration tests in tests/ directory

rust testing integration
by Marcus Chen 1 tab
rust
use std::borrow::Cow;

fn ensure_prefix(input: &str) -> Cow<str> {
    if input.starts_with("https://") {
        Cow::Borrowed(input)
    } else {

Cow for clone-on-write to avoid unnecessary allocations

rust optimization strings
by Marcus Chen 1 tab
rust
use anyhow::{Context, Result};
use std::fs;

fn load_config(path: &str) -> Result<String> {
    fs::read_to_string(path)
        .with_context(|| format!("failed to read config from {}", path))

anyhow::Context for adding error context without custom types

rust error-handling cli
by Marcus Chen 1 tab
rust
pub struct Server {
    host: String,
    port: u16,
    workers: usize,
}

Builder pattern for complex struct initialization

rust patterns builder
by Marcus Chen 1 tab
rust
use std::sync::{Arc, Mutex};
use std::thread;

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

Send and Sync traits for safe concurrency guarantees

rust concurrency traits
by Marcus Chen 1 tab
rust
const MAX_SIZE: usize = 1024;

const fn square(n: u32) -> u32 {
    n * n
}

const and const fn for compile-time evaluation

rust const performance
by Marcus Chen 1 tab