Three common patterns: load it all into memory, iterate line-by-line, or stream bytes. Pick by file size — `read_to_string` is convenient but bad for huge files.
When you don't know the JSON shape up-front, parse into `serde_json::Value` and navigate via index / get(). Type-safe pattern matching converts back to Rust types.
PostgreSQL `RETURNING *` returns the rows affected by an INSERT/UPDATE/DELETE — no separate SELECT round-trip needed. SQL Server has `OUTPUT`; MySQL added `RETURNING` in MariaDB and 8.0.31+.
Declare data integrity rules right in the schema — primary keys, foreign keys, unique constraints, NOT NULL, CHECK constraints, defaults. The DB enforces them so application bugs can't corrupt your data.
Build a custom context manager without writing a class — just a generator with one `yield`. The code before yield runs on enter, after yield runs on exit (even on exception).
`by lazy { ... }` runs the block on first access, caches the result. Default mode is thread-safe (synchronized). Perfect for expensive initialization where you might never need the value.
Like sealed classes, but for interfaces — and a class can implement multiple sealed interfaces. Cleaner state modeling when you want "this is both a Loadable and a Cacheable".
`String` is an owned, growable heap allocation; `&str` is a borrowed view into a UTF-8 buffer. Function params should usually take `&str`; return types use `String` when ownership is needed.
Generates a random 6-digit hex colour string. Useful for seeding avatar backgrounds, chart series colours, placeholder UI elements, and testing colour-dependent components. The crypto version produces a more unpredictable result suitable for generating unique palette tokens.
Runs an array of async tasks with a maximum concurrency cap, preventing you from firing hundreds of requests simultaneously. Processes items in batches, moving to the next as slots free up. Essential when hitting rate-limited APIs or processing large datasets without overwhelming the server.