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.

4330 bites

Page 133

Go & Rust1 min read

Structuring a Go CLI that fetches a URL

Parse args with the flag package, http.Get the URL, check err and status, defer resp.Body.Close, copy body to stdout, exit non-zero on failure.

Go & Rust2 min read

Handling Result and errors in a Rust web handler

Handler returns Result, the ? operator early-returns errors, a custom error type implements IntoResponse to map to 500, success returns 200 with data.

Go & Rust1 min read

In-memory rate limiter middleware in Go

Use a token-bucket limiter (golang.org/x/time/rate), guard a per-client map with sync.Mutex, wrap http.Handler so requests over the limit get 429.

Go & Rust1 min read

Logging middleware wrapping an http.Handler in Go

Middleware has signature func(http.Handler) http.Handler, records start time, calls next.ServeHTTP, then logs method, URL, and elapsed duration; chaining works because the wrapper is itself a…

Go & Rust2 min read

Static dispatch over Write with generics in Rust

Write generically over the std::io::Write trait with a type parameter W: Write, letting the compiler monomorphize and inline per concrete type, avoiding the vtable indirection of Box<dyn Write>.

Go & Rust2 min read

Using context.Context across microservice calls in Go

Context carries cancellation, deadlines, and values; pass ctx as first arg, set one WithTimeout at the edge, attach a request ID via WithValue, thread it through downstream calls so all cancel…

Go & Rust1 min read

Rust Send and Sync marker traits explained

Send means a value can move across threads, Sync means a reference can be shared; Rc uses non-atomic refcounts, Arc uses atomic ones.

Go & Rust1 min read

Architecting an L7 proxy in Go versus Rust

Go offers GC and cheap goroutines for fast delivery but tail-latency GC pauses; Rust offers ownership and async/await for predictable latency at higher complexity.

Go & Rust2 min read

Why Pin is needed for self-referential Futures

Async blocks compile to state machines that can hold references into their own storage; Pin guarantees the value will not move so those internal pointers stay valid across polls.

Go & Rust1 min read

Fearless concurrency: Rust compile-time vs Go runtime

Rust uses ownership plus Send/Sync to reject data races at compile time; Go encourages channels but still allows races, with the runtime race detector catching them at test…

Go & Rust2 min read

Rust lifetimes versus Go garbage-collected lifetimes

A lifetime is a compile-time region a reference is valid for; annotations like 'a relate input and output reference durations; Go instead uses garbage collection and escape analysis.

Go & Rust1 min read

Criterion: the standard Rust benchmarking library

Criterion runs on stable Rust, collects many samples, applies statistical analysis with confidence intervals, and compares against saved baselines to detect regressions.

Go & Rust1 min read

Structural Go interfaces versus nominal Rust traits

Go interfaces are satisfied implicitly by method shape (structural); Rust traits must be explicitly implemented (nominal).

Go & Rust1 min read

Goroutines and channels versus ownership-based concurrency

Go uses cheap goroutines and CSP-style channels to coordinate by communication; Rust uses ownership plus Send/Sync to make data races a compile error.

Go & Rust2 min read

Go (T, error) versus Rust Result for error handling

Go returns a separate error value you may ignore; Rust wraps success or error in one Result enum the compiler forces you to handle. Go favors simplicity, Rust favors compile-enforced safety.

Go & Rust1 min read

Go interface-constraint generics versus Rust trait bounds

Go constrains type parameters with interfaces and may use dictionaries/shape stenciling; Rust uses trait bounds with full monomorphization for zero-cost specialization.

Go & Rust2 min read

Go's mandatory runtime versus Rust's minimal runtime

Go ships a GC and goroutine scheduler in every binary, ideal for services; Rust has only a tiny runtime and no GC, enabling embedded, kernels, and WASM.

Go & Rust1 min read

Go interfaces versus Rust traits and macros at scale

Go uses reflection over interface{} (e.g. encoding/json) for runtime flexibility; Rust uses traits plus derive/proc macros (e.g. serde) for compile-time, zero-cost code generation.

Go & Rust2 min read

Go slices versus Rust Vec growth and reallocation

Both are a (pointer, length, capacity) triple over a heap buffer that reallocates and copies on growth, roughly doubling; key difference is Go slices share backing arrays and have no ownership…

Go & Rust2 min read

Designing a logging abstraction: Go interfaces vs Rust traits

Define a Logger interface/trait with a write method; Go interfaces are always dynamically dispatched; Rust lets you choose static dispatch (impl Trait/generics) or…