All Patterns

Master advanced Rust patterns with detailed explanations, interactive examples, and real-world use cases.

Filter

Showing 78 of 78 patterns

Split Borrowing
Advanced
Borrow different parts of a struct simultaneously
🔐Ownership & Borrowing Patterns
borrowingmutabilitystructs
🎮 Playground
Interior Mutability Patterns
Advanced
When to use Cell, RefCell, and Mutex
🔐Ownership & Borrowing Patterns
cellrefcellmutex
🎮 Playground
Self-Referential Structures
Expert
Using Pin and safe patterns for self-references
🔐Ownership & Borrowing Patterns
pinunsafeadvanced
🎮 Playground
Lifetime Elision Mastery
Advanced
Complex lifetime scenarios and elision rules
🔐Ownership & Borrowing Patterns
lifetimesreferences
🎮 Playground
RAII Guards
Intermediate
Custom drop guards for resource management
🔐Ownership & Borrowing Patterns
dropresourcesraii
🎮 Playground
Rc/Arc Usage Patterns
Intermediate
When to use each and cycle prevention
🎯Smart Pointers & Interior Mutability
rcarcreference-counting
🎮 PlaygroundWASM
Weak Pointers
Advanced
Breaking cycles in graph structures
🎯Smart Pointers & Interior Mutability
weakgraphscycles
🎮 Playground
Clone-on-Write (Cow)
Intermediate
Zero-copy until mutation needed
🎯Smart Pointers & Interior Mutability
cowoptimizationcloning
🎮 Playground
Custom Smart Pointers
Expert
Building your own Box-like types
🎯Smart Pointers & Interior Mutability
derefdropcustom
🎮 Playground
Custom Error Types
Intermediate
Implementing std::error::Error properly
⚠️Error Handling Excellence
errorcustom-types
🎮 Playground
Error Composition
Intermediate
Using thiserror and anyhow effectively
⚠️Error Handling Excellence
thiserroranyhowcomposition
🎮 Playground
Result Combinators
Intermediate
and_then, or_else, map_err mastery
⚠️Error Handling Excellence
resultcombinatorsfunctional
🎮 Playground
Error Context
Advanced
Maintaining error chains and context
⚠️Error Handling Excellence
contexterror-chains
🎮 Playground
Associated Types vs Generics
Advanced
When to use which approach
🎨Advanced Trait System
traitsassociated-typesgenerics
🎮 Playground
Higher-Ranked Trait Bounds
Expert
for<'a> patterns and HRTBs
🎨Advanced Trait System
hrtblifetimesadvanced
🎮 Playground
Trait Objects & Dynamic Dispatch
Intermediate
Box<dyn Trait> patterns and vtables
🎨Advanced Trait System
dyndynamic-dispatchvtable
🎮 Playground
Blanket Implementations
Advanced
Implementing traits for generic types
🎨Advanced Trait System
blanketimplgenerics
🎮 Playground
Orphan Rules & Newtype
Intermediate
Working with external traits
🎨Advanced Trait System
orphan-rulesnewtypewrapper
🎮 Playground
Custom Future Implementation
Expert
Building futures from scratch
Async/Await & Futures
futureasyncpoll
🎮 Playground
Stream Processing
Advanced
Async iterators and backpressure
Async/Await & Futures
streamasync-iteratorbackpressure
🎮 Playground
Select/Join Patterns
Intermediate
Concurrent future composition
Async/Await & Futures
selectjointokio
🎮 Playground
Cancellation & Timeouts
Advanced
Proper cleanup patterns
Async/Await & Futures
cancellationtimeoutcleanup
🎮 Playground
Declarative Macros
Intermediate
macro_rules! patterns and repetition
🔮Macro Mastery
macro_rulesdeclarative
🎮 Playground
Procedural Macros
Expert
Derive, attribute, and function-like
🔮Macro Mastery
proc-macroderiveattribute
🎮 Playground
DSL Creation
Expert
Domain-specific languages in Rust
🔮Macro Mastery
dslmacrosyntax
🎮 Playground
Iterator Composition
Intermediate
How iterators optimize to machine code
🚀Zero-Cost Abstractions
iteratoroptimizationzero-cost
🎮 Playground
Monomorphization
Advanced
Understanding generic compilation
🚀Zero-Cost Abstractions
genericscompilationoptimization
🎮 Playground
Const Evaluation
Advanced
Compile-time computation
🚀Zero-Cost Abstractions
constcompile-timeconst-fn
🎮 Playground
State Machines in Types
Advanced
Compile-time state validation
🎭Type-State Programming
typestatestate-machinetypes
🎮 PlaygroundWASM
Builder with TypeState
Advanced
Enforcing build order at compile time
🎭Type-State Programming
buildertypestateapi-design
🎮 Playground
Phantom Types
Advanced
Zero-runtime-cost type information
🎭Type-State Programming
phantomzero-costmarker
🎮 Playground
Send/Sync Bounds
Intermediate
Understanding thread safety
🔀Concurrency Patterns
sendsyncthread-safety
🎮 Playground
Channel Patterns
Intermediate
mpsc, oneshot, broadcast patterns
🔀Concurrency Patterns
channelmpsccommunication
🎮 Playground
Lock-Free Data Structures
Expert
Using atomics correctly
🔀Concurrency Patterns
atomiclock-freeconcurrent
🎮 Playground
Scoped Threads
Advanced
Borrowing across thread boundaries
🔀Concurrency Patterns
scopethreadsborrowing
🎮 Playground
Safe Abstractions Over Unsafe
Expert
Encapsulation patterns for unsafe code
Unsafe & FFI
unsafeencapsulationsafety
🎮 Playground
FFI Boundaries
Advanced
C interop best practices
Unsafe & FFI
ffic-interopextern
🎮 Playground
Memory Layout
Advanced
#[repr(C)] and layout guarantees
Unsafe & FFI
reprlayoutmemory
🎮 Playground
Memory Layout Optimization
Advanced
Struct packing and alignment
Performance Optimization
memoryalignmentoptimization
🎮 Playground
SIMD Patterns
Expert
Portable SIMD and platform-specific
Performance Optimization
simdvectorizationperformance
🎮 Playground
Benchmarking with Criterion
Intermediate
Proper performance measurement
Performance Optimization
benchmarkcriterionperformance
🎮 Playground
Binary Trees & BST
Intermediate
Tree structures with ownership-aware design
🏗️Data Structures & Algorithms
treesbstrecursion+1
🎮 Playground
Graph Algorithms
Advanced
BFS, DFS, Dijkstra with Rust idioms
🏗️Data Structures & Algorithms
graphsbfsdfs+1
🎮 Playground
Sorting Algorithms
Intermediate
Implement and optimize sorting in Rust
🏗️Data Structures & Algorithms
sortingquicksortmergesort+1
🎮 Playground
Dynamic Programming
Advanced
Memoization and tabulation patterns
🏗️Data Structures & Algorithms
dpmemoizationoptimization
🎮 Playground
Hash Tables
Advanced
Custom hash maps and hashing strategies
🏗️Data Structures & Algorithms
hashmaphashingcollections
🎮 Playground
Heaps & Priority Queues
Intermediate
Binary heaps and priority-based structures
🏗️Data Structures & Algorithms
heappriority-queuebinary-heap
🎮 Playground
Linked Lists
Advanced
Singly and doubly linked lists with ownership patterns
🏗️Data Structures & Algorithms
linked-listownershippointers+1
🎮 Playground
Stacks & Queues
Intermediate
LIFO and FIFO data structures with various implementations
🏗️Data Structures & Algorithms
stackqueuedeque+1
🎮 Playground
Tries (Prefix Trees)
Advanced
Efficient string storage and prefix-based operations
🏗️Data Structures & Algorithms
trieprefix-treeautocomplete+1
🎮 Playground
Factory Pattern
Intermediate
Object creation with traits and generics
🎭Design Patterns in Rust
factorycreationaltraits
🎮 Playground
Builder Pattern
Intermediate
Fluent APIs and compile-time validation
🎭Design Patterns in Rust
buildercreationalfluent-api
🎮 Playground
Observer Pattern
Advanced
Event-driven systems with channels
🎭Design Patterns in Rust
observerbehavioralevents
🎮 Playground
Strategy Pattern
Intermediate
Interchangeable algorithms with traits
🎭Design Patterns in Rust
strategybehavioraltraits
🎮 Playground
Adapter Pattern
Intermediate
Interface compatibility with wrappers
🎭Design Patterns in Rust
adapterstructuralwrapper
🎮 Playground
Decorator Pattern
Advanced
Runtime behavior extension
🎭Design Patterns in Rust
decoratorstructuralcomposition
🎮 Playground
Singleton Pattern
Intermediate
Global state with OnceLock and lazy initialization
🎭Design Patterns in Rust
singletoncreationalglobal-state+1
🎮 Playground
Command Pattern
Advanced
Encapsulate requests as objects with undo/redo support
🎭Design Patterns in Rust
commandbehavioralundo-redo+1
🎮 Playground
State Pattern
Advanced
State machines with enum and trait-based approaches
🎭Design Patterns in Rust
statebehavioralstate-machine+1
🎮 Playground
Visitor Pattern
Advanced
Separate algorithms from object structure
🎭Design Patterns in Rust
visitorbehavioralast+1
🎮 Playground
Unit Testing
Intermediate
Test modules, assertions, and organization
🧪Testing Strategies
testingunit-testsassertions
🎮 Playground
Integration Testing
Intermediate
Testing across module boundaries
🧪Testing Strategies
testingintegrationtests-dir
🎮 Playground
Property-Based Testing
Advanced
Generative testing with proptest
🧪Testing Strategies
proptestquickcheckgenerative
🎮 Playground
Fuzzing
Advanced
Finding bugs with cargo-fuzz
🧪Testing Strategies
fuzzingcargo-fuzzsecurity
🎮 Playground
Mocking & Test Doubles
Intermediate
Isolating dependencies in tests
🧪Testing Strategies
mockingmockalltest-doubles
🎮 Playground
REST API Design
Intermediate
RESTful services with Axum/Actix
🌐API Design Patterns
restaxumactix+1
🎮 Playground
GraphQL APIs
Advanced
GraphQL with async-graphql
🌐API Design Patterns
graphqlasync-graphqljuniper
🎮 Playground
gRPC Services
Advanced
High-performance RPC with tonic
🌐API Design Patterns
grpctonicprotobuf
🎮 Playground
Error Responses
Intermediate
Consistent error handling for APIs
🌐API Design Patterns
errorsapiresponses
🎮 Playground
Rate Limiting
Intermediate
Protecting APIs from abuse
🌐API Design Patterns
rate-limitthrottlingmiddleware
🎮 Playground
Retry Patterns
Intermediate
Exponential backoff and retry strategies
🛡️Resilience Patterns
retrybackofffault-tolerance
🎮 Playground
Circuit Breaker
Advanced
Preventing cascade failures
🛡️Resilience Patterns
circuit-breakerfault-toleranceresilience
🎮 Playground
Bulkhead Pattern
Advanced
Isolating failures with resource pools
🛡️Resilience Patterns
bulkheadisolationsemaphore
🎮 Playground
Graceful Degradation
Advanced
Fallbacks and partial functionality
🛡️Resilience Patterns
degradationfallbackresilience
🎮 Playground
Workspace Patterns
Intermediate
Multi-crate project organization
📦Module System & Architecture
workspacecargomonorepo
🎮 Playground
Crate Design
Intermediate
Public APIs and module visibility
📦Module System & Architecture
cratepubapi-design
🎮 Playground
Feature Flags
Intermediate
Conditional compilation strategies
📦Module System & Architecture
featurescfgconditional
🎮 Playground
Dependency Management
Intermediate
Versioning and dependency strategies
📦Module System & Architecture
dependenciescargosemver
🎮 Playground