Advanced concepts in Go & Rust, page 2
Rust Build Scripts: Compiling More Than Just Rust
A build.rs script is a pre-compilation hook for tasks outside Rust's scope, like compiling C code or generating Rust modules. It's essential for FFI or code generation. A key footgun: cfg! checks the host, not the target, breaking cross-compilation.
Rust Cargo Features: Conditional Compilation & Dependencies
Cargo features are compile-time switches for conditional compilation and optional dependencies. They let you build tailored versions of a crate from one source, like an image library that only includes code for the formats you need.
Rust Build Profiles: Tune for Speed vs. Debugging
Rust build profiles are presets for the compiler, trading off compile time and debuggability for runtime speed. Use the dev profile for quick iteration and the release profile for production. The footgun is benchmarking without the --release flag.
I/O Stream Abstractions
I/O stream abstractions like Go's io.Reader and io.Writer model data as a flow of bytes behind a tiny interface, so files, sockets, buffers and encoders compose interchangeably without each one knowing the others' concrete type.
Go's `context` Package: Propagating Cancellation and Deadlines
Go's context package is a lifeline for requests, carrying cancellation signals, deadlines, and values across function calls and goroutines. It's essential for I/O-bound operations to prevent resource leaks.
Foreign Function Interface (FFI): Calling Other Languages
Think of an FFI as a universal adapter, letting your program call functions written in another language. It's how modern code in Rust or Go can reuse battle-tested C libraries for tasks like graphics or system calls, avoiding a complete rewrite.
Go Fuzz Testing: Automated Bug Discovery
Go's fuzz testing automatically generates strange inputs to crash your code, finding bugs you'd never think to test. It's ideal for stress-testing parsers or security-sensitive functions.
Fuzz Testing in Rust with cargo-fuzz
Fuzz testing automatically finds bugs by feeding your code pseudo-random inputs. Use cargo-fuzz to stress-test parsers and APIs that handle untrusted data. The main footgun is assuming random bytes are enough; effective fuzzing needs structure-aware inputs.
Go Execution Tracer: Pinpointing Concurrency Bottlenecks
Go's Execution Tracer creates a visual timeline of your program, capturing goroutine state changes, syscalls, and GC events. It's essential for diagnosing subtle concurrency issues like lock contention. The main footgun is misusing annotations for work.
Rust Procedural Macros: Code That Writes Code
Procedural macros are compile-time functions that write Rust code for you. They power common patterns like Serde's #[derive(Serialize)]. The main footgun is hygiene: generated code can clash with local variables, so authors must use absolute paths to be…
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 `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.
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.
Daemonizing Go/Rust Apps: Let the OS Do It
Daemonizing an app means running it as a background service, detached from your terminal. This is essential for web servers or job processors. The common footgun is writing custom daemon logic instead of using a system service manager like systemd.
We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.
See open roles