mirror of
https://github.com/Noratrieb/ice-104649.git
synced 2026-01-16 21:35:02 +01:00
lol no futures
This commit is contained in:
parent
7e80955154
commit
08a9431055
1 changed files with 27 additions and 50 deletions
77
src/main.rs
77
src/main.rs
|
|
@ -1,3 +1,4 @@
|
||||||
|
use fut::Stream;
|
||||||
use std::{
|
use std::{
|
||||||
future::Future,
|
future::Future,
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
|
|
@ -18,7 +19,6 @@ pub fn spawn<T: Future>(future: T) -> JoinHandle<T::Output> {
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
use fut::StreamExt;
|
|
||||||
mod fut {
|
mod fut {
|
||||||
use std::{
|
use std::{
|
||||||
future::Future,
|
future::Future,
|
||||||
|
|
@ -29,40 +29,7 @@ mod fut {
|
||||||
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>>;
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct Iter<I> {
|
|
||||||
iter: I,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn iter<I>(i: I) -> Iter<I::IntoIter>
|
|
||||||
where
|
|
||||||
I: IntoIterator,
|
|
||||||
{
|
|
||||||
Iter {
|
|
||||||
iter: i.into_iter(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<I> Stream for Iter<I>
|
|
||||||
where
|
|
||||||
I: Iterator,
|
|
||||||
{
|
|
||||||
type Item = I::Item;
|
|
||||||
|
|
||||||
fn poll_next(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Option<I::Item>> {
|
|
||||||
Poll::Ready(self.iter.next())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: ?Sized> StreamExt for T where T: Stream {}
|
|
||||||
|
|
||||||
fn assert_future<F, T>(t: T) -> T {
|
|
||||||
t
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait StreamExt: Stream {
|
|
||||||
fn map<T, F>(self, f: F) -> Map<Self, F>
|
fn map<T, F>(self, f: F) -> Map<Self, F>
|
||||||
where
|
where
|
||||||
F: FnMut(Self::Item) -> T,
|
F: FnMut(Self::Item) -> T,
|
||||||
|
|
@ -89,7 +56,30 @@ mod fut {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use = "streams do nothing unless polled"]
|
pub struct Iter<I> {
|
||||||
|
iter: I,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn iter<I>(i: I) -> Iter<I::IntoIter>
|
||||||
|
where
|
||||||
|
I: IntoIterator,
|
||||||
|
{
|
||||||
|
Iter {
|
||||||
|
iter: i.into_iter(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<I> Stream for Iter<I>
|
||||||
|
where
|
||||||
|
I: Iterator,
|
||||||
|
{
|
||||||
|
type Item = I::Item;
|
||||||
|
|
||||||
|
fn poll_next(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Option<I::Item>> {
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Map<St, F> {
|
pub struct Map<St, F> {
|
||||||
stream: St,
|
stream: St,
|
||||||
f: F,
|
f: F,
|
||||||
|
|
@ -118,27 +108,14 @@ mod fut {
|
||||||
{
|
{
|
||||||
type Output = R;
|
type Output = R;
|
||||||
fn call_once(self, arg: A) -> R {
|
fn call_once(self, arg: A) -> R {
|
||||||
self(arg)
|
loop {}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait FnMut1<A>: FnOnce1<A> {
|
|
||||||
fn call_mut(&mut self, arg: A) -> Self::Output;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T, A, R> FnMut1<A> for T
|
|
||||||
where
|
|
||||||
T: FnMut(A) -> R,
|
|
||||||
{
|
|
||||||
fn call_mut(&mut self, arg: A) -> R {
|
|
||||||
self(arg)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<St, F> Stream for &Map<St, F>
|
impl<St, F> Stream for &Map<St, F>
|
||||||
where
|
where
|
||||||
St: Stream,
|
St: Stream,
|
||||||
F: FnMut1<St::Item>,
|
F: FnOnce1<St::Item>,
|
||||||
{
|
{
|
||||||
type Item = F::Output;
|
type Item = F::Output;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue