-
Currently, Current LimitationsThe pre-GAT design of Current ImplementationHere's what the current implementation looks like: pub trait Stream {
type Item;
// Required method
fn poll_next(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Self::Item>>;
// Provided method
fn size_hint(&self) -> (usize, Option<usize>);
} GAT-Based Improved VersionHere's how the trait could be redesigned using GATs: pub trait Stream {
type Item<'a> where Self: 'a;
// Required method
fn poll_next(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Self::Item<'_>>>;
// Provided method
fn size_hint(&self) -> (usize, Option<usize>);
} BenefitsThe GAT-based approach offers several advantages:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The tokio-stream crate was intended as a temporary thing until the standard library adds the |
Beta Was this translation helpful? Give feedback.
The tokio-stream crate was intended as a temporary thing until the standard library adds the
Stream
trait. If you want to improve the trait, I suggest you get involved with the efforts in the stdlib.