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
fff0122f88
commit
272b2d844f
1 changed files with 9 additions and 27 deletions
36
src/main.rs
36
src/main.rs
|
|
@ -5,9 +5,9 @@ use std::{
|
||||||
task::{Context, Poll},
|
task::{Context, Poll},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct JoinHandle<T>(T);
|
pub struct FutResult<T>(T);
|
||||||
|
|
||||||
impl<T> Future for JoinHandle<T> {
|
impl<T> Future for FutResult<T> {
|
||||||
type Output = Result<T, ()>;
|
type Output = Result<T, ()>;
|
||||||
|
|
||||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||||
|
|
@ -15,10 +15,6 @@ impl<T> Future for JoinHandle<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn spawn<T>(future: T) -> JoinHandle<T> {
|
|
||||||
loop {}
|
|
||||||
}
|
|
||||||
|
|
||||||
mod fut {
|
mod fut {
|
||||||
use std::{
|
use std::{
|
||||||
future::Future,
|
future::Future,
|
||||||
|
|
@ -46,7 +42,7 @@ mod fut {
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn buffer_unordered(self, n: impl Into<Option<usize>>) -> BufferUnordered<Self>
|
fn buffer_unordered(self) -> BufferUnordered<Self>
|
||||||
where
|
where
|
||||||
Self::Item: Future,
|
Self::Item: Future,
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
|
|
@ -55,24 +51,10 @@ mod fut {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Iter<I> {
|
pub struct Empty;
|
||||||
iter: I,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn iter<I>(i: I) -> Iter<I::IntoIter>
|
impl Stream for Empty {
|
||||||
where
|
type Item = String;
|
||||||
I: IntoIterator,
|
|
||||||
{
|
|
||||||
Iter {
|
|
||||||
iter: i.into_iter(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<I> Stream for Iter<I>
|
|
||||||
where
|
|
||||||
I: Iterator,
|
|
||||||
{
|
|
||||||
type Item = I::Item;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Map<St, F> {
|
pub struct Map<St, F> {
|
||||||
|
|
@ -139,9 +121,9 @@ mod fut {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let bodies = fut::iter([])
|
let bodies = fut::Empty
|
||||||
.map(|url: String| spawn(Result::Ok(url)))
|
.map(|url| FutResult(Result::Ok(url)))
|
||||||
.buffer_unordered(0);
|
.buffer_unordered();
|
||||||
|
|
||||||
bodies.for_each(|b| async {
|
bodies.for_each(|b| async {
|
||||||
match b {
|
match b {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue