mirror of
https://github.com/Noratrieb/ice-104649.git
synced 2026-01-14 20:45:01 +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},
|
||||
};
|
||||
|
||||
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, ()>;
|
||||
|
||||
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 {
|
||||
use std::{
|
||||
future::Future,
|
||||
|
|
@ -46,7 +42,7 @@ mod fut {
|
|||
loop {}
|
||||
}
|
||||
|
||||
fn buffer_unordered(self, n: impl Into<Option<usize>>) -> BufferUnordered<Self>
|
||||
fn buffer_unordered(self) -> BufferUnordered<Self>
|
||||
where
|
||||
Self::Item: Future,
|
||||
Self: Sized,
|
||||
|
|
@ -55,24 +51,10 @@ mod fut {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct Iter<I> {
|
||||
iter: I,
|
||||
}
|
||||
pub struct Empty;
|
||||
|
||||
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;
|
||||
impl Stream for Empty {
|
||||
type Item = String;
|
||||
}
|
||||
|
||||
pub struct Map<St, F> {
|
||||
|
|
@ -139,9 +121,9 @@ mod fut {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let bodies = fut::iter([])
|
||||
.map(|url: String| spawn(Result::Ok(url)))
|
||||
.buffer_unordered(0);
|
||||
let bodies = fut::Empty
|
||||
.map(|url| FutResult(Result::Ok(url)))
|
||||
.buffer_unordered();
|
||||
|
||||
bodies.for_each(|b| async {
|
||||
match b {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue