expression

Distinguish operation completion from readiness

Windows I/O completion ports deliver completion packets for associated overlapped operations (and can receive application-posted packets). A completion includes operation identity and outcome; a failed wait is different from a dequeued failed operation. This portable model represents only application-level packet processing, not the Win32 ABI. Expected stdout (not executed): 1: 4 bytes 2: failed Common mistake: Treating a completion packet as permission to initiate the same operation again without checking its outcome. Run only in the isolated fixture runner, not a public code playground.

Formal Syntax & Structure

rust syntaxrust
CreateIoCompletionPort; GetQueuedCompletionStatus (Win32 APIs)

Working Example

Example Snippetrust
enum Packet { Completed { id: u64, bytes: usize }, Failed { id: u64 } }fn main() {    let packets = [Packet::Completed { id: 1, bytes: 4 }, Packet::Failed { id: 2 }];    for packet in packets {        match packet {            Packet::Completed { id, bytes } => println!("{id}: {bytes} bytes"),            Packet::Failed { id } => println!("{id}: failed"),        }    }}
Rust Reference