I/O exchanges data between a program and an external destination or source, including files, devices, and networks. In Rust, stateful I/O requires deliberate error handling, and functions performing I/O should generally return Result. section 6.4 section 8.2
Choose an execution model according to how the program spends time:
- Synchronous I/O blocks while an operation completes, executing tasks sequentially. section 8.2
- Asynchronous I/O is nonblocking: tasks interleave other work during I/O waits, avoiding thread context-switch overhead and supporting many lightweight tasks. section 8.2
- Test I/O and other stateful operations as logic, while relying on Rust’s type system for reference validity, mutation safety, and race prevention. section 6.4
Typical waiting operations
Filesystem access and socket interaction provide direct I/O examples; waiting for a timer or computing a hash illustrates the same asynchronous control-flow pattern for other slow operations. section 8.2
Compare blocking synchronous I/O with nonblocking asynchronous I/O across waiting and result-processing time. section 8.2



