get rid of futures

This commit is contained in:
nora 2025-10-17 23:00:46 +02:00
parent e9b6576d2b
commit 5ce26e9089
5 changed files with 62 additions and 103 deletions

View file

@ -1,16 +1,63 @@
use futures_util::future::{Map, MapOk};
use std::pin::Pin;
struct MapOk2<Fut, F>(Fut, F);
impl<Fut, F> Future for MapOk2<Fut, F>
pub trait FnOnce1<A> {
type Output;
fn call_once(self, arg: A) -> Self::Output;
}
impl<T, A, R> FnOnce1<A> for T
where
Map<Fut, F>: Future,
T: FnOnce(A) -> R,
{
type Output = <Map<Fut, F> as Future>::Output;
type Output = R;
fn call_once(self, arg: A) -> R {
self(arg)
}
}
pub struct MapOkFn<F>(F);
impl<F, T, E> FnOnce1<Result<T, E>> for MapOkFn<F>
where
F: FnOnce1<T>,
{
type Output = Result<F::Output, E>;
fn call_once(self, arg: Result<T, E>) -> Self::Output {
arg.map(|x| self.0.call_once(x))
}
}
pub struct Map<Fut, F> {
inner: (Fut, F),
}
impl<Fut, F, T> Future for Map<Fut, F>
where
Fut: Future,
F: FnOnce1<Fut::Output, Output = T>,
{
type Output = T;
fn poll(
self: Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Self::Output> {
self: core::pin::Pin<&mut Self>,
cx: &mut core::task::Context<'_>,
) -> core::task::Poll<Self::Output> {
loop {}
}
}
pub struct MapOk<Fut, F> {
inner: Map<Fut, MapOkFn<F>>,
}
impl<Fut, F> Future for MapOk<Fut, F>
where
Map<Fut, MapOkFn<F>>: Future,
{
type Output = <Map<Fut, MapOkFn<F>> as Future>::Output;
fn poll(
self: core::pin::Pin<&mut Self>,
cx: &mut core::task::Context<'_>,
) -> core::task::Poll<Self::Output> {
loop {}
}
}
@ -53,7 +100,6 @@ pub async fn bar_baz() {
}
// 1
// 2
#[derive(proc_macro_thing::MyMacro)]
#[helper]