diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..ecfa81f --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "futures-rs"] + path = futures-rs + url = git@github.com:rust-lang/futures-rs.git diff --git a/futures-rs b/futures-rs new file mode 160000 index 0000000..86f0626 --- /dev/null +++ b/futures-rs @@ -0,0 +1 @@ +Subproject commit 86f0626e8b4d4484c381a37a492b2fff28dfaa92 diff --git a/src/main.rs b/src/main.rs index 3778f60..0463dc5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,17 @@ -use futures::{stream, Future, StreamExt}; +use std::{ + future::Future, + pin::Pin, + task::{Context, Poll}, +}; + +use futures::{stream, StreamExt}; pub struct JoinHandle(T); impl Future for JoinHandle { type Output = Result; - fn poll( - self: std::pin::Pin<&mut Self>, - cx: &mut std::task::Context<'_>, - ) -> std::task::Poll { + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { loop {} } } @@ -17,8 +20,128 @@ pub fn spawn(future: T) -> JoinHandle { loop {} } +pub trait Stream { + /// Values yielded by the stream. + type Item; + fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll>; + #[inline] + fn size_hint(&self) -> (usize, Option) { + (0, None) + } +} + +pub struct Iter { + iter: I, +} + +impl Unpin for Iter {} + +pub(crate) fn assert_stream(stream: S) -> S +where + S: Stream, +{ + stream +} + +pub fn iter(i: I) -> Iter +where + I: IntoIterator, +{ + assert_stream::(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()) + } + + fn size_hint(&self) -> (usize, Option) { + self.iter.size_hint() + } +} + +impl Stream for &S { + type Item = S::Item; + + fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { + todo!() + } +} +impl Stream for &mut S { + type Item = S::Item; + + fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { + todo!() + } +} +trait UwuStream: Stream { + fn map(self, f: F) -> Map + where + F: FnMut(Self::Item) -> T, + Self: Sized, + { + loop {} + } + fn buffer_unordered(self, n: impl Into>) -> BufferUnordered + where + Self::Item: Future, + Self: Sized, + { + loop {} + } +} + +impl UwuStream for S {} +pub struct Map { + stream: St, + f: F, +} +impl Stream for Map +where + St: Stream, + F: FnMut(St::Item), +{ + type Item = F::Output; + + fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { + loop {} + } + + fn size_hint(&self) -> (usize, Option) { + self.stream.size_hint() + } +} +pub struct BufferUnordered +where + St: Stream, +{ + uwu: St, +} + +impl Stream for BufferUnordered +where + St: Stream, + St::Item: Future, +{ + type Item = ::Output; + + fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { + loop {} + } + + fn size_hint(&self) -> (usize, Option) { + loop {} + } +} fn main() { - let bodies = stream::iter([]) + let bodies = iter([]) .map(|url: String| spawn(async { Result::Ok(url) })) .buffer_unordered(0);