mirror of
https://github.com/Noratrieb/ice-104649.git
synced 2026-01-14 12:35:02 +01:00
lol no futures
This commit is contained in:
parent
17c5b42921
commit
7e80955154
1 changed files with 3 additions and 92 deletions
95
src/main.rs
95
src/main.rs
|
|
@ -22,58 +22,20 @@ use fut::StreamExt;
|
||||||
mod fut {
|
mod fut {
|
||||||
use std::{
|
use std::{
|
||||||
future::Future,
|
future::Future,
|
||||||
num::NonZeroUsize,
|
|
||||||
ops::DerefMut,
|
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
task::{Context, Poll},
|
task::{Context, Poll},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[must_use = "streams do nothing unless polled"]
|
|
||||||
pub trait Stream {
|
pub trait Stream {
|
||||||
type Item;
|
type Item;
|
||||||
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>>;
|
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>>;
|
||||||
#[inline]
|
|
||||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
|
||||||
(0, None)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<S: ?Sized + Stream + Unpin> Stream for &mut S {
|
|
||||||
type Item = S::Item;
|
|
||||||
|
|
||||||
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
|
||||||
S::poll_next(Pin::new(&mut **self), cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
|
||||||
(**self).size_hint()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P> Stream for Pin<P>
|
|
||||||
where
|
|
||||||
P: DerefMut + Unpin,
|
|
||||||
P::Target: Stream,
|
|
||||||
{
|
|
||||||
type Item = <P::Target as Stream>::Item;
|
|
||||||
|
|
||||||
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
|
||||||
self.get_mut().as_mut().poll_next(cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
|
||||||
(**self).size_hint()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
#[must_use = "streams do nothing unless polled"]
|
|
||||||
pub struct Iter<I> {
|
pub struct Iter<I> {
|
||||||
iter: I,
|
iter: I,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I> Unpin for Iter<I> {}
|
|
||||||
|
|
||||||
pub fn iter<I>(i: I) -> Iter<I::IntoIter>
|
pub fn iter<I>(i: I) -> Iter<I::IntoIter>
|
||||||
where
|
where
|
||||||
I: IntoIterator,
|
I: IntoIterator,
|
||||||
|
|
@ -92,10 +54,6 @@ mod fut {
|
||||||
fn poll_next(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Option<I::Item>> {
|
fn poll_next(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Option<I::Item>> {
|
||||||
Poll::Ready(self.iter.next())
|
Poll::Ready(self.iter.next())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
|
||||||
self.iter.size_hint()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ?Sized> StreamExt for T where T: Stream {}
|
impl<T: ?Sized> StreamExt for T where T: Stream {}
|
||||||
|
|
@ -110,7 +68,7 @@ mod fut {
|
||||||
F: FnMut(Self::Item) -> T,
|
F: FnMut(Self::Item) -> T,
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
Map::new(self, f)
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn for_each<Fut, F>(self, f: F) -> ForEach<Self, Fut, F>
|
fn for_each<Fut, F>(self, f: F) -> ForEach<Self, Fut, F>
|
||||||
|
|
@ -119,7 +77,7 @@ mod fut {
|
||||||
Fut: Future<Output = ()>,
|
Fut: Future<Output = ()>,
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
assert_future::<(), _>(ForEach::new(self, f))
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn buffer_unordered(self, n: impl Into<Option<usize>>) -> BufferUnordered<Self>
|
fn buffer_unordered(self, n: impl Into<Option<usize>>) -> BufferUnordered<Self>
|
||||||
|
|
@ -127,7 +85,7 @@ mod fut {
|
||||||
Self::Item: Future,
|
Self::Item: Future,
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
BufferUnordered::new(self, n.into())
|
loop {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -137,12 +95,6 @@ mod fut {
|
||||||
f: F,
|
f: F,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<St, F> Map<St, F> {
|
|
||||||
pub(crate) fn new(stream: St, f: F) -> Self {
|
|
||||||
Self { stream, f }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<St, F> Stream for Map<St, F>
|
impl<St, F> Stream for Map<St, F>
|
||||||
where
|
where
|
||||||
St: Stream,
|
St: Stream,
|
||||||
|
|
@ -153,10 +105,6 @@ mod fut {
|
||||||
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
|
||||||
self.stream.size_hint()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait FnOnce1<A> {
|
pub trait FnOnce1<A> {
|
||||||
|
|
@ -197,10 +145,6 @@ mod fut {
|
||||||
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
|
||||||
self.stream.size_hint()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ForEach<St, Fut, F> {
|
pub struct ForEach<St, Fut, F> {
|
||||||
|
|
@ -209,21 +153,6 @@ mod fut {
|
||||||
future: Option<Fut>,
|
future: Option<Fut>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<St, Fut, F> ForEach<St, Fut, F>
|
|
||||||
where
|
|
||||||
St: Stream,
|
|
||||||
F: FnMut(St::Item) -> Fut,
|
|
||||||
Fut: Future<Output = ()>,
|
|
||||||
{
|
|
||||||
pub(super) fn new(stream: St, f: F) -> Self {
|
|
||||||
Self {
|
|
||||||
stream,
|
|
||||||
f,
|
|
||||||
future: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<St, Fut, F> Future for ForEach<St, Fut, F>
|
impl<St, Fut, F> Future for ForEach<St, Fut, F>
|
||||||
where
|
where
|
||||||
St: Stream,
|
St: Stream,
|
||||||
|
|
@ -242,20 +171,6 @@ mod fut {
|
||||||
St: Stream,
|
St: Stream,
|
||||||
{
|
{
|
||||||
stream: St,
|
stream: St,
|
||||||
max: Option<NonZeroUsize>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<St> BufferUnordered<St>
|
|
||||||
where
|
|
||||||
St: Stream,
|
|
||||||
St::Item: Future,
|
|
||||||
{
|
|
||||||
pub(super) fn new(stream: St, n: Option<usize>) -> Self {
|
|
||||||
Self {
|
|
||||||
stream: stream,
|
|
||||||
max: n.and_then(NonZeroUsize::new),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<St> Stream for BufferUnordered<St>
|
impl<St> Stream for BufferUnordered<St>
|
||||||
|
|
@ -268,10 +183,6 @@ mod fut {
|
||||||
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
|
||||||
loop {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue