rust

rust
use color_eyre::Result;

fn might_fail() -> Result<()> {
    Err(color_eyre::eyre::eyre!("Something went wrong"))
}

color-eyre for beautiful error reports with backtraces

rust error-handling cli
by Marcus Chen 1 tab
rust
use serde::{Deserialize, Deserializer};

#[derive(Debug, Deserialize)]
pub struct ListFilter {
    #[serde(default)]
    pub status: Status,

Parse URL Query Strings into a Typed Filter Struct with Defaults in Rust

rust serde query-string
by codesnips 3 tabs
rust
#[derive(Debug, Clone)]
pub enum Outcome {
    Approve,
    Review,
    Reject(String),
}

Modeling and Evaluating a Decision Tree with Recursive Rust Enums

rust enums recursion
by codesnips 3 tabs
rust
use std::mem;

fn main() {
    let mut x = 5;
    let mut y = 10;

std::mem helpers for low-level memory manipulation

rust memory
by Marcus Chen 1 tab
rust
use std::error::Error;
use std::fmt;
use std::io;
use std::num::ParseIntError;

#[derive(Debug)]

Custom Error Enum With From Conversions for the ? Operator in Rust

rust error-handling traits
by codesnips 3 tabs
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
struct Logger {
    name: String,
}

impl Drop for Logger {
    fn drop(&mut self) {

Drop trait for custom cleanup logic

rust traits memory-management
by Marcus Chen 1 tab
toml
[package]
name = "my-app"
version = "0.1.0"

[dependencies]
tokio = "1"

Cargo.lock for reproducible builds

rust cargo dependencies
by Marcus Chen 1 tab
rust
use dashmap::DashMap;
use std::time::Instant;

pub struct TokenBucket {
    tokens: f64,
    last_refill: Instant,

Token-Bucket Rate Limiter Middleware for Axum Using DashMap

axum rust rate-limiting
by codesnips 3 tabs
rust
struct Locked;
struct Unlocked;

struct Door<State> {
    _state: std::marker::PhantomData<State>,
}

Type state pattern for compile-time state machines

rust patterns type-safety
by Marcus Chen 1 tab
rust
use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize)]
pub struct SignupRequest {
    pub email: String,
    pub password: String,

Accumulating Field-Level Validation Errors in Rust Signup Forms

rust validation error-handling
by codesnips 3 tabs
rust
use tokio::time::{sleep, Duration};

async fn fetch_data() -> String {
    sleep(Duration::from_millis(100)).await;
    "data".to_string()
}

async/await with tokio for concurrent I/O without blocking threads

rust async tokio
by Marcus Chen 1 tab