{}

Rust Anti-patterns

Tempting on the surface, wrong underneath — a what-not-to-do catalog with canonical alternatives.

Arc<Mutex<Vec<T>>> as default shared state
Using a global mutex-guarded vector when message passing would do.
concurrencyperformancedeadlock
Arc<RwLock<T>> as the default shared-state container
Reaching for Arc<RwLock<T>> for read-mostly state when arc-swap or atomics fit.
concurrencyperformancecontention
Arc when scoped threads would do
Wrapping borrowable data in Arc just to spawn a thread.
concurrencythreadingownership
block_on inside an async fn
Calling Runtime::block_on or futures::executor::block_on from already-async code.
asyncruntimedeadlock
Blocking call inside async
std::thread::sleep or sync I/O inside an async fn.
asyncruntimeperformance
Boxing values that fit comfortably on the stack
Box<T> reached for as a default container instead of by need.
memoryallocationperformance
Box<dyn Fn> as the default closure type
Heap-allocating every closure when a generic parameter would inline.
performanceclosuresmonomorphization
Clone-cascade
Sprinkling .clone() across the call site to silence the borrow checker.
performanceownershipallocation
Collect-then-iter round trip
Materializing an iterator into Vec just to iterate it again.
iterationperformanceallocation
dyn Trait where impl Trait or generics fit
Reaching for Box<dyn Trait> by reflex when a static-dispatched parameter would do.
genericstraitsdispatch
Error from format string
Box<dyn Error>::from(format!("...")) instead of a typed error.
error-handlinglibrary-design
format! in a hot loop
Allocating a fresh String per iteration to build messages that get discarded or appended.
performanceallocationformatting