Rust Examples
Rust render aligned plain-text terminal table
Computes column widths from headers and cells, then joins padded rows with pipes and a dashed separator.
Rust field-level input validation with error list
Validates signup fields and returns every failure as a field name plus message instead of stopping at the first.
Rust base64 encode and decode with validation
Encodes bytes with the standard alphabet and padding, then decodes while rejecting bad lengths and characters.
Rust percent-encode and parse URL query strings
Percent-encodes query components and parses '?'-prefixed strings into decoded key/value pairs for ASCII URLs.
Rust parse flat JSON objects with indexed errors
Decodes a flat object of string key/value pairs and reports missing braces, colons, or quotes with pair indexes.
Rust bounded worker pool over item chunks
Runs a fallible map across a fixed number of scoped threads and collects results in input order.
Rust HTTP GET with timeouts and JSON field extraction
Fetches a page over raw TCP with read/write timeouts, isolates the response body, and pulls a string field out of JSON.
Rust environment config with defaults and validation
Reads host, port, and debug flag from environment variables with defaults, parsing and range validation.
Rust token bucket rate limiter with burst capacity
Allows bursts up to a capacity while refilling tokens at a steady per-second rate on each acquire call.
Rust multi-key stable sort with nulls last
Sorts records by active flag, missing scores last, score descending, then name, using a stable comparator.
Rust bounded LRU cache with recency tracking
Keeps at most a fixed number of entries, evicting the least recently used key and refreshing hits in O(n).
Rust split any iterator into fixed-size Vec batches
Collects an iterator into vectors of at most N items, with a NonZeroUsize guard and a final partial batch.
Rust read a text file line by line with BufReader
Streams a text file line by line with BufReader and returns an io::Result vector of lines.
Rust deep clone and recursive merge for nested maps
Deep-copies a nested enum tree, then merges an override patch recursively with map keys preserved.
Rust capped exponential backoff retry helper
Retries a fallible closure with capped exponential backoff and small jitter, returning the last error.