expression
Discard staged results on cancellation
For a bounded batch of in-memory changes, separate preparation from publication. If cancellation occurs before publication, discard the staged values. This protects only the simulated buffer; file durability and transactions require additional mechanisms. Fixture: Expected stdout (not executed): [1, 2, 3] Expected stderr: (empty) Expected exit: 0 Common mistake: Calling partial work a completed result or claiming that Drop reverses external effects.
Formal Syntax & Structure
rust syntaxrust
if cancelled { drop(staged); ... }Working Example
Example Snippetrust
fn main() { let original = vec![1, 2, 3]; let mut staged = Vec::new(); let mut cancelled = false; for item in &original { if cancelled { break; } staged.push(item * 2); if staged.len() == 2 { cancelled = true; } } let result = if cancelled { original } else { staged }; println!("{result:?}");}