lol no futures

This commit is contained in:
nora 2022-11-20 22:09:54 +01:00
parent 592e86e3f3
commit 4433f6b891
No known key found for this signature in database

View file

@ -10,65 +10,59 @@ impl<T> Project for FutResult<T> {
type Assoc = Result<T, ()>; type Assoc = Result<T, ()>;
} }
mod fut { use crate::Project;
use std::future::Future;
use crate::Project; pub trait Stream {
pub trait Stream {
type Item; type Item;
fn for_each<Fut, F>(self, f: F) -> ForEach<Self, Fut, F> fn for_each<Fut, F>(self, f: F) -> ForEach<Self, F>
where where
F: FnMut(Self::Item) -> Fut, F: FnMut(Self::Item) -> Fut,
Fut: Future<Output = ()>,
Self: Sized, Self: Sized,
{ {
loop {} loop {}
} }
} }
pub fn map<T, F>(f: F) -> Map<F> pub fn map<T, F>(f: F) -> Map<F>
where where
F: FnMut(String) -> T, F: FnMut(String) -> T,
{ {
loop {} loop {}
} }
pub struct Map<F>(F); pub struct Map<F>(F);
pub trait FnOnce1<A> { pub trait FnOnce1<A> {
type Output; type Output;
fn call_once(self, arg: A) -> Self::Output; fn call_once(self, arg: A) -> Self::Output;
} }
impl<T, A, R> FnOnce1<A> for T impl<T, A, R> FnOnce1<A> for T
where where
T: FnOnce(A) -> R, T: FnOnce(A) -> R,
{ {
type Output = R; type Output = R;
fn call_once(self, arg: A) -> R { fn call_once(self, arg: A) -> R {
loop {} loop {}
} }
} }
impl<F> Stream for Map<F> impl<F> Stream for Map<F>
where where
F: FnOnce1<String>, F: FnOnce1<String>,
F::Output: Project, F::Output: Project,
{ {
type Item = <F::Output as Project>::Assoc; type Item = <F::Output as Project>::Assoc;
} }
pub struct ForEach<St, Fut, F> { pub struct ForEach<St, F> {
stream: St, stream: St,
f: F, f: F,
future: Fut,
}
} }
fn main() { fn main() {
let bodies = fut::map(|url| FutResult(Result::Ok(url))); let bodies = map(|url| FutResult(Result::Ok(url)));
bodies.for_each(|b| async { bodies.for_each(|b| async {
match b { match b {