expression

Keep overlapped state alive through cancellation

A cancellation request is not a completion guarantee. Windows may finish an operation normally, cancel it, or fail it. Keep the operation state and buffers alive until completion is established according to the API contract. This safe ownership model represents a possible cancellation sequence; it does not issue native calls. Expected stdout (not executed): requested: true, retained: true pending: false Common mistake: Freeing the OVERLAPPED state or buffer immediately after requesting cancellation. Run only in the isolated fixture runner, not a public code playground.

Formal Syntax & Structure

rust syntaxrust
CancelIoEx; observe final completion before releasing OVERLAPPED

Working Example

Example Snippetrust
fn main() {    let mut pending = Some(Box::new([0u8; 8]));    let cancel_requested = true;    println!("requested: {cancel_requested}, retained: {}", pending.is_some());    // Model receipt of the terminal completion, not the cancellation request.    let completed = pending.take().unwrap();    drop(completed);    println!("pending: {}", pending.is_some());}
Rust Reference