Skip to content
tezvyn:

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 130

Go & Rust2 min read

Rust's Module-to-Filesystem Mapping

Rust's module system maps directly to your file system. A mod foo; statement tells the compiler to look for foo.rs or foo/mod.rs. This is how you organize any multi-file Rust project.

Go & Rust2 min read

Go's `internal` Directory: Private by Convention

Go's internal directory creates private packages within your module, making them inaccessible to external projects. Use it for helper logic you don't want to support as a public API.

Go & Rust2 min read

Rust Cargo Workspaces: A Monorepo Control Panel

A Cargo Workspace is a control panel for a multi-crate Rust project, unifying dependencies and build artifacts. Use it for related binaries and libraries to ensure consistent builds.

Go & Rust2 min read

Stack vs. Heap: Where Go Puts Your Data

The stack is a fast, last-in-first-out region for local, fixed-size data. The heap is slower, flexible memory for dynamic data or values that escape a function's scope.

Go & Rust2 min read

Rust's Copy Trait: Implicit Bitwise Duplication

Rust's Copy trait makes assignments duplicate a value instead of moving it, allowing the original to still be used. It's an implicit, bitwise copy for simple types like integers.

Go & Rust2 min read

Rust's `Drop` Trait: Automatic Resource Cleanup

Rust's Drop trait provides automatic, deterministic cleanup, like a destructor. It's used to release external resources like file handles or network sockets when a value goes out of scope. The key footgun: you cannot implement Drop on a Copy type.

Go & Rust2 min read

RAII in Rust: Automatic Cleanup via Scope

RAII ties a resource's lifetime to its owner's scope. When the owner variable is dropped, Rust automatically cleans up the resource, preventing leaks. This applies to heap memory, file handles, and locks. The footgun: cleanup is deterministic, not like a GC.

Go & Rust2 min read

Rust's Lifetime Elision: When You Can Skip 'a

Lifetime elision lets you omit explicit lifetimes ('a) in function signatures. The compiler infers them from common patterns, like a function taking one reference and returning one.

GC vs. Ownership: Two Paths to Memory Safety
Go & Rust2 min read

GC vs. Ownership: Two Paths to Memory Safety

Rust's ownership model provides memory safety at compile-time, aiming for C++-level performance without a garbage collector. This makes it ideal for systems programming where resource control is key. The footgun is assuming all "safe" languages are equal.

Go & Rust2 min read

Go's GC: Low-Latency Collection with Tri-color Marking

Go's GC uses a tri-color algorithm to find unused memory concurrently, avoiding long pauses. It's crucial for low-latency services. The main footgun is breaking the invariant: a 'finished' (black) object must never point to a new (white) one without notifying…

Go & Rust2 min read

Rust's Interior Mutability: Mutating 'Immutable' Data

Interior mutability lets you modify data through an immutable reference, moving Rust's borrow checks from compile-time to runtime. It's used in single-threaded code when the compiler can't verify safe access.

Go & Rust2 min read

Rust's NLL: Smarter Borrows Based on Use, Not Scope

Non-Lexical Lifetimes (NLL) make Rust's borrow checker smarter. A borrow's lifetime ends after its last use, not at the end of its code block. This allows modifying data after a borrow is finished, even if the reference variable is still in scope.

Go & Rust2 min read

Go's `error` Interface: Errors Are Values

In Go, an error is any value that can describe its own failure string. Functions like os.Open return an error to signal problems. The footgun is only checking for nil and ignoring the rich, structured data a custom error type can provide.

Go & Rust2 min read

Rust's Option<T>: Handling Absence Safely

Rust's Option<T> is a type-safe box that holds either a value (Some(T)) or nothing (None), eliminating null pointer errors. Use it for function returns that might fail or for optional struct fields. The footgun is .unwrap(), which panics on None.

Go & Rust2 min read

Handling Errors with Rust's Result Enum

Rust's Result enum makes error handling explicit. Instead of returning a value that might be an error code, functions return either Ok(value) or Err(error). It's used for recoverable failures like I/O.

Go & Rust2 min read

Go Error Wrapping: Preserving Context, Not Just Text

Go's error wrapping adds context without losing the original error's type. Use fmt.Errorf with %w to create a chain of errors, then inspect it with errors.Is or errors.As. The footgun is using %v, which just formats the error as a string.

Go & Rust2 min read

Rust's Question Mark Operator (?): Propagate Errors, Not Boilerplate

The ? operator cleans up Rust error handling by propagating Err values. Instead of a verbose match block, you append ? to a Result or Option, and it automatically returns the error if present, letting you focus on the happy path.

Go & Rust2 min read

Result: Handling Recoverable Errors in Rust

Rust handles recoverable errors with the Result<T, E> enum, forcing you to deal with both success (Ok) and failure (Err) paths. This shows up when a function like File::open might fail.

Go & Rust2 min read

Go's Panic/Recover: For Exceptional Errors Only

Go's panic/recover is a last-resort error mechanism, not a try/catch replacement. A panic unwinds a goroutine's stack until a recover in a defer'd function catches it. It's used to keep a server alive when one request fails catastrophically.

Go & Rust2 min read

Rust's `panic!`: When to Crash Your Program Intentionally

Rust's panic! is an emergency stop for unrecoverable bugs, intentionally crashing the current thread. It's for impossible states where continuing is dangerous, not for recoverable errors like failed I/O—use Result for that.