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 129

Go & Rust2 min read

Go Pointers: Memory Addresses, Not Math

Go pointers are street addresses for data. Instead of copying a large struct, you pass its memory address. This lets functions modify the original value and is critical for performance.

Go & Rust2 min read

Rust's Variable Shadowing: Re-binding, Not Mutating

Shadowing lets you declare a new variable with the same name, making the old one inaccessible. It's used to transform a value, like changing its type, without making it mutable. The footgun is confusing shadowing (let x = ...) with reassignment (x = ...).

Go & Rust2 min read

Rust's Turbofish (`::<>`): When the Compiler Needs Help

The turbofish (::<>) is your tool to resolve ambiguity when Rust's compiler can't infer a type or trait. Use it when a type implements multiple traits with same-named methods, forcing the compiler to pick the one you specify.

Go & Rust2 min read

Using Box<T> for Heap Allocation in Rust

Rust's Box<T> is a smart pointer that moves data from the stack to the heap. It's essential for creating recursive types, like linked lists, whose size would otherwise be infinite. The main footgun is in FFI: never wrap a C-allocated pointer in a Box.

Go & Rust2 min read

Go Maps: Your Built-in Hash Table

Go maps are the language's built-in hash tables for fast key-value lookups. Use make(map[K]V) to initialize one before writing. The biggest footgun is writing to a nil map, which causes a runtime panic. Always initialize your maps first.

Go & Rust2 min read

Rust Vectors: Your Go-To Growable List

A Vec<T> is Rust's smart, growable array. It automatically gets more memory when full, keeping items together for fast access. Use it for lists of unknown size. The footgun: frequent reallocations can be slow if you don't pre-allocate capacity.

Go & Rust2 min read

Rust HashMap: Fast, Secure Key-Value Storage

A Rust HashMap is like a dictionary, mapping unique keys to values for fast lookups. Use it for caching or frequency counting. The footgun: never modify a key after insertion, as changing its hash will break the map's internal logic.

Go & Rust2 min read

Rust Slices (&[T]): Views Without Ownership

A Rust slice is a borrowed view into a contiguous sequence of data, like an array or Vec, without taking ownership. Use it to write functions that operate on parts of a collection efficiently. The footgun: a slice cannot outlive the data it points to.

Go & Rust2 min read

Rust's Two String Types: String vs. &str

Think of String as an owned, growable text buffer on the heap, while &str is a borrowed, fixed-size view into string data. This distinction is key to Rust's memory safety. Functions often take &str to flexibly accept both types.

Go & Rust2 min read

Rust Enums: Attaching Data Directly to Variants

A Rust enum variant can carry its own data, acting like a mini-struct. This is perfect for modeling states with different payloads, like a Result that holds either a value or an error. The footgun is using a separate struct to pair an enum with.

Go & Rust2 min read

Go's sync.Map: A Specialized Concurrent Map

Go's sync.Map is a concurrent map optimized for keys written once and read many times. It's ideal for long-lived caches, but it's not a generic replacement for a map with a mutex. The footgun is using it for frequent writes, which can be slower.

Go & Rust2 min read

Rust's Rc<T>: Shared Ownership on a Single Thread

Rust's Rc<T> enables shared ownership within a single thread. Think of it as a counter on a heap-allocated resource: cloning an Rc increments the count, and the resource is freed only when the count hits zero. Use it for graph nodes with multiple owners.

Go & Rust2 min read

Rust's Arc<T>: Share Data Ownership Across Threads

Rust's Arc<T> lets multiple threads share ownership of heap data. It's a smart pointer that counts references atomically. Use it for shared caches or config. The footgun: Arc only makes sharing safe, not mutation—you still need a Mutex for that.

Go & Rust2 min read

Rust Crates: Your Unit of Compilation

A crate is the smallest unit of code the Rust compiler handles—either a runnable program (binary) or a shareable library. A package, defined by Cargo.toml, bundles one or more crates. The footgun: a package can have many binaries but only one library.

Go & Rust2 min read

Rust Modules: Your Code's File System

Think of Rust modules as a file system for your code, grouping logic and hiding details. You declare them with mod, and Rust finds the code in corresponding files. The footgun: items are private by default, so you must use pub to expose them.

Go & Rust2 min read

Go's Entry Point: The `main` Package and Function

A Go program's entry point is package main. The compiler finds this package and its main() function to create a runnable binary. The footgun is naming a library main; this name is reserved for executables and will cause build confusion.

Go & Rust2 min read

Rust Item Visibility: Private by Default

In Rust, all items are private by default. Think of modules as locked rooms; you need the pub keyword to unlock the door. This is crucial for creating a public API or letting modules interact.

Go & Rust2 min read

Rust Methods: Attaching Behavior to Data

Rust methods are functions attached to your data structures, defined in an impl block. Instead of do_thing(my_struct), you call my_struct.do_thing(). The key footgun: instance.name() calls a method, but instance.name accesses a field.

Go & Rust2 min read

go.mod: Root of Go Module Identity

A go.mod file anchors a Go module, declaring its canonical path and dependencies to turn a directory into a versioned unit. Every project needs one at its root, and the path dictates how others import your packages.

Go & Rust2 min read

Cargo.toml: Rust's Project Recipe

Cargo.toml is your Rust project's recipe, telling the compiler what to build and what dependencies it needs. It defines metadata, production dependencies, and dev-only dependencies for testing.