rust

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 crate::paginator::Paginator;

#[derive(Clone)]
pub struct Row {
    pub cells: Vec<String>,
}

Streaming Paginated PDF Report Sections From a Domain Model in Rust

rust pdf pagination
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
rust
// In a proc-macro crate:
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, DeriveInput};

#[proc_macro_derive(MyTrait)]

Procedural macros for custom derives and attributes

rust macros metaprogramming
by Marcus Chen 1 tab
rust
#![feature(asm)]

fn add_asm(a: u64, b: u64) -> u64 {
    let result: u64;
    unsafe {
        asm!(

Inline assembly for critical performance hotspots

rust assembly performance
by Marcus Chen 1 tab