All bites
The whole library, newest first. Filter by what you are here for, or pick a topic if you already know.
4247 bites
Page 134
Rust Const Generics: Parameterize by Value, Not Just Type
Const generics let Rust types be parameterized by values, not just other types. This allows writing code generic over array sizes, like Matrix<T, const N: usize>, ensuring dimensions are checked at compile time.
Rust's Pin: Fixing a Value's Memory Address
Pin<P> tells the Rust compiler a value must not move from its memory location. Think of it as nailing an object to a specific spot on the memory shelf. This is crucial for self-referential types, like those in async runtimes.
Go Assembly: A Semi-Abstract Instruction Set
Go's assembler isn't a direct mapping to machine code; it's a semi-abstract instruction set. A MOV might become a clear or load. This is what you see with go tool compile -S. The footgun is assuming your assembly maps 1:1 to the final machine code.
Rust's `extern` Block: Talking to Other Languages
An extern block is Rust's contract for calling code from other languages, like C. You declare external functions and statics, promising they exist. Use it for FFI to call system libraries, but know all calls are unsafe as Rust can't verify them.
Rust's `libc` Crate: Speaking the OS's Language
The libc crate is Rust's dictionary for C types, letting you talk to the OS. Use it for system calls or linking C libraries, like when building low-level network tools.
Rust: Bridging C Strings with CStr and CString
CString and CStr are Rust's safe wrappers for C's nul-terminated strings. CString builds a C-compatible string to pass *out* of Rust; CStr interprets one coming *in*. Use them for any FFI calls.
Rust: Expose Functions to C with `#[no_mangle]`
The #[no_mangle] attribute tells the Rust compiler not to alter a function's name, exposing a stable symbol for C code to call. Use it with extern "C" to create Rust libraries for other languages. The footgun is forgetting extern "C", causing crashes.
FFI Error Handling: Translation and Unwinding
FFI error handling is a translation layer: foreign errors must become Rust Results before safe code sees them, or you risk UB. You do this in -sys wrappers around C libraries. The footgun: foreign exceptions unwinding across boundary without -unwind ABI is UB.
The C Application Binary Interface
An ABI is the contract a library exposes for in-process machine code access. You see this whenever a compiled program calls into a compiled library at the binary level.
Rust's `bindgen`: Auto-Generate FFI to C/C++
bindgen is a translator that reads C/C++ headers and writes the unsafe Rust FFI code to call them. It's used to integrate Rust with existing C libraries, like system APIs or legacy code, saving you from writing bindings by hand.
cbindgen: Auto-generate C/C++ Headers for Rust
cbindgen automatically generates C/C++ headers for your Rust code, saving you from writing tedious FFI boilerplate. Use it when exposing a Rust library to other languages. Its feature set is ad-hoc, so it may not support your specific edge case out of the box.

Go Cobra: Build Complex CLIs Like `kubectl`
Cobra gives your Go CLI a command tree, like git remote add. It's for apps with nested commands and persistent flags, not just simple tools. The footgun is using it for a single command when Go's flag package would suffice.
Rust's `clap`: Build CLIs by Describing Them
clap lets you define a Rust struct representing your CLI's arguments, and it generates the parser, help text, and validation. It's used for building any Rust CLI, but its feature-richness can increase binary size over simpler alternatives.
The Builder Pattern: Constructing Complex Objects in Rust
The Builder pattern lets you construct complex objects step-by-step using a chain of method calls. It's crucial in Rust for structs with many optional fields, since the language lacks default arguments.

Go's Worker Pool Pattern: Capping Concurrency
A worker pool caps concurrency by using a fixed number of goroutines to process jobs from a queue. Use it for rate-limiting API calls or processing files without spawning unlimited goroutines.
Go's Functional Options Pattern for Flexible APIs
The functional options pattern uses functions to set optional struct fields, making APIs flexible and readable. It's common for complex constructors like servers or DB clients.
Rust's Deref Trait: Smart Pointers Acting Like Data
The Deref trait lets a "smart pointer" type act like the data it contains, making wrappers transparent. It enables calling an inner type's methods directly on a wrapper, like using &str methods on a String. Its deref() method must never fail.
Terminal User Interfaces (TUIs): GUIs for the Console
A TUI is a graphical interface built from text, offering rich interactivity without leaving the console. Use them for system monitoring (btop), file management, or database clients. The footgun: don't confuse them with CLIs; TUIs are stateful apps.
Rust's Tower Service: One Trait for Clients, Servers, and Middleware
Tower's Service trait is a universal API for async requests. It models any 'request -> future<response>' flow, unifying clients, servers, and middleware. Use it for HTTP servers or database clients. The footgun: ignoring poll_ready bypasses backpressure.
The FromRequest Trait: Consuming Request Bodies in Axum
Axum's FromRequest trait defines how to create a type by consuming an HTTP request body. It's the core of extractors like Json<T> that deserialize POST data. The footgun: you can only use one FromRequest extractor per handler, as it consumes the body.