Part two of an async interview series with cramertj covers the design of the Stream trait in Rust's futures crate. Key topics include the distinction between 'detached' (current) and 'attached' (streaming) iterators/streams, where attached streams could return references to internal buffers for efficiency. The post explains why Generic Associated Types (GATs) are needed to express attached streams, why stabilizing Stream shouldn't wait for GATs, and how detached streams can be converted to attached ones. Also discussed: implications for syntactic sugar like for-await loops and generator functions, plus the uninitialized buffer problem in AsyncRead/AsyncWrite traits.

10m read timeFrom smallcultfollowing.com
Post cover image
Table of contents
The need for “streaming” streams and iteratorsTerminology note: Detached/attached instead of “streaming”The natural way to write “attached” streams is with GATs“Attached” streams would be used differently than the current onesConcerns with blocking the streaming trait“Detached” streams can be converted into “attached” onesThings that consume streams would typically want an attached streamSyntactic support for streams and iteratorsThe AsyncRead and AsyncWrite traitsConclusion
1 Impression