Rust Examples

RustOct 23, 2026

Rust render aligned plain-text terminal table

Computes column widths from headers and cells, then joins padded rows with pipes and a dashed separator.

formattingtableterminal
000
RustOct 23, 2026

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.

errorsvalidationforms
000
RustOct 23, 2026

Rust base64 encode and decode with validation

Encodes bytes with the standard alphabet and padding, then decodes while rejecting bad lengths and characters.

decodingencodingbase64
000
RustOct 23, 2026

Rust percent-encode and parse URL query strings

Percent-encodes query components and parses '?'-prefixed strings into decoded key/value pairs for ASCII URLs.

query-stringurlencoding
000
RustOct 23, 2026

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.

error-handlingparsingjson
000
RustOct 23, 2026

Rust bounded worker pool over item chunks

Runs a fallible map across a fixed number of scoped threads and collects results in input order.

concurrencyworker-poolthreads
000
RustOct 23, 2026

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.

timeoutshttpjson
000
RustOct 23, 2026

Rust environment config with defaults and validation

Reads host, port, and debug flag from environment variables with defaults, parsing and range validation.

configurationenv-varsvalidation
000
RustOct 23, 2026

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.

token-bucketrate-limitthrottling
000
RustOct 23, 2026

Rust multi-key stable sort with nulls last

Sorts records by active flag, missing scores last, score descending, then name, using a stable comparator.

sortingrecordscomparator
000
RustOct 23, 2026

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).

boundedlrucache
000
RustOct 23, 2026

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.

iteratorbatcheschunks
000
RustOct 23, 2026

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.

buffered-readerlinesfile-io
000
RustOct 23, 2026

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.

mergeclonecollections
000
RustOct 23, 2026

Rust capped exponential backoff retry helper

Retries a fallible closure with capped exponential backoff and small jitter, returning the last error.

error-handlingbackoffretry
000