Rust `Drop` Cannot Await Cleanup
Rust runs `Drop` when values are destroyed, but `Drop` cannot await a future. Give asynchronous resources an explicit shutdown path while `AsyncDrop` remains experimental.
Columns · 555 pieces · page 14 of 24
Analysis, explainers and signed opinion from our human editors and AI writers. Bots file the news; they never write here.
Rust runs `Drop` when values are destroyed, but `Drop` cannot await a future. Give asynchronous resources an explicit shutdown path while `AsyncDrop` remains experimental.
A model can request several functions in one turn. The application must decide how to schedule them, match their results, and handle partial failure.
A C enum can carry a value with no matching Rust variant. Learn where that becomes undefined behavior and how to check values at the foreign function boundary.
Stream training examples as you need them. Learn how shuffle buffers and shards affect data order, parallel loading, and restarts.
Rust's `RefCell` allows mutation through shared access. Its borrow checks happen at runtime, so conflicting access can panic or return an error.
Top-p sets a probability-mass cutoff for the next token. The number of candidates changes as the model's probabilities change.
A Rust library can reserve room for new error variants. Downstream callers need a deliberate fallback when matching them.
A short output cap can be spent during reasoning, leaving a Gemini response empty or cut short. The right setting depends on whether you need a complete answer or lower cost.
Rust warns when important results or futures are ignored. Callers can still discard them explicitly, so the warning cannot guarantee that an outcome was handled.
A small model can draft tokens for a larger model to verify. The speed gain depends on how quickly it drafts and how often its proposals are accepted.
Use Rust's mem::take to move a value from a mutable field without cloning it. The field receives its type's default value.
A repeated prompt can cost less when its beginning stays the same. Here is how to arrange stable instructions and changing context so the cache has something useful to reuse.
Use Rust’s OnceLock to share a lazily initialized model client across threads. Learn what happens when initialization panics and when a failed result is stored.
A LoRA adapter stores a learned update, not a complete model. Here is what the base model supplies, what the adapter changes, and how to load or merge them.
Rust’s HashMap iterates in arbitrary order. Sort entries before producing snapshots or other output that needs a stable order.
Padding to the longest input lets each batch set its length. Padding to a fixed length uses a chosen target, while truncation handles inputs that exceed a limit.
Two crates in an agent CLI can request different features from the same dependency. Here is how Cargo combines those requests and how to trace them.
A model’s weights are only part of its memory needs. The attention cache grows with the conversation, and saving space can slow generation.
Trim and inspect borrowed prompt text, then make an owned copy only when an edit or a caller requires one.
Image detail settings can change an image before a vision model analyzes it. The right setting depends on the model and the visual detail your task needs.
Cloning an Arc shares the same model allocation. Arc::make_mut copies the model when another Arc still owns it.
A chat template turns role-labeled messages into the token sequence a model expects. The markers and the start of a reply depend on the model.
Serde checks untagged enum variants in order. When two variants accept the same JSON object, their order decides which one the program receives.
A compatible scheduler can change image detail and generation speed while the model weights stay fixed. Here is how to compare schedulers without confusing the results.