diff --git a/src/main.rs b/src/main.rs index 17aa712..fea5779 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use fut::Stream; use std::{ future::Future, pin::Pin, @@ -18,7 +19,6 @@ pub fn spawn(future: T) -> JoinHandle { loop {} } -use fut::StreamExt; mod fut { use std::{ future::Future, @@ -29,40 +29,7 @@ mod fut { pub trait Stream { type Item; fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll>; - } - #[derive(Debug, Clone)] - pub struct Iter { - iter: I, - } - - pub fn iter(i: I) -> Iter - where - I: IntoIterator, - { - Iter { - iter: i.into_iter(), - } - } - - impl Stream for Iter - where - I: Iterator, - { - type Item = I::Item; - - fn poll_next(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll> { - Poll::Ready(self.iter.next()) - } - } - - impl StreamExt for T where T: Stream {} - - fn assert_future(t: T) -> T { - t - } - - pub trait StreamExt: Stream { fn map(self, f: F) -> Map where F: FnMut(Self::Item) -> T, @@ -89,7 +56,30 @@ mod fut { } } - #[must_use = "streams do nothing unless polled"] + pub struct Iter { + iter: I, + } + + pub fn iter(i: I) -> Iter + where + I: IntoIterator, + { + Iter { + iter: i.into_iter(), + } + } + + impl Stream for Iter + where + I: Iterator, + { + type Item = I::Item; + + fn poll_next(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll> { + loop {} + } + } + pub struct Map { stream: St, f: F, @@ -118,27 +108,14 @@ mod fut { { type Output = R; fn call_once(self, arg: A) -> R { - self(arg) - } - } - - pub trait FnMut1: FnOnce1 { - fn call_mut(&mut self, arg: A) -> Self::Output; - } - - impl FnMut1 for T - where - T: FnMut(A) -> R, - { - fn call_mut(&mut self, arg: A) -> R { - self(arg) + loop {} } } impl Stream for &Map where St: Stream, - F: FnMut1, + F: FnOnce1, { type Item = F::Output;