Recipes

Small Rust patterns, labeled with the reason they exist.

Rustjar recipes are intentionally narrow. They are not grand architectures; they are reusable moves for the recurring parts of Rust work: shaping errors, passing ownership cleanly, keeping async tasks observable, and deciding when a type should be stricter than a string. Each recipe should be easy to paste into a review discussion, but it also needs enough context to prevent cargo-cult reuse.

Error context

Prefer errors that name the operation, the remote system, and the recoverable action.

Ownership boundary

Move ownership at API edges; borrow inside tight scopes where the caller can still reason locally.

Iterator cleanup

Use iterator chains when they expose intent, but stop before the debug path disappears.

Async handoff

Write cancellation and timeout expectations beside the spawned work, not in a later comment.

Serde shape

Separate wire structs from domain structs when external contracts change faster than the model.

Rust recipe notes with compiler diagnostics and a practical coding notebook