Diffstat (limited to 'src/effect.rs')
| -rw-r--r-- | src/effect.rs | 69 |
1 files changed, 34 insertions, 35 deletions
diff --git a/src/effect.rs b/src/effect.rs index b52f94a..71e4aec 100644 --- a/src/effect.rs +++ b/src/effect.rs @@ -5,33 +5,30 @@ use core::{ task::{Context, Poll, RawWaker, RawWakerVTable, Waker}, }; -use crate::{higher_ranked_trait, higher_ranked_type}; +use crate::{bijective_higher_ranked_type, bijective_higher_ranked_trait}; -higher_ranked_trait! { - pub type class SendFuture['ctx, Output]: [for<'lt> core::future::Future<Output = Output> + Send + 'lt] +bijective_higher_ranked_trait! { + pub type class SendFuture[][Output]: [for<'lt> core::future::Future<Output = Output> + Sized + Send + 'lt] where { Output: Send, } - for where { - Output: 'lt, - } } /// Trait for effects. -pub trait Effect<'ctx>: Send + 'static { - type Future<T: Send>: SendFuture::Trait<'ctx, T>; +pub trait Effect: Send + 'static { + type Future<T: Send>: SendFuture::MemberType<T>; - fn wrap<'a, F>(future: F) -> SendFuture::T<'a, 'ctx, Self::Future<F::Output>, F::Output> + fn wrap<'a, F>(future: F) -> SendFuture::T<'a, Self::Future<F::Output>, F::Output> where F: core::future::Future + Send + 'a, <F as core::future::Future>::Output: Send; - fn ready<'a, T: Send>(value: T) -> SendFuture::T<'a, 'ctx, Self::Future<T>, T>; + fn ready<'a, T: Send>(value: T) -> SendFuture::T<'a, Self::Future<T>, T>; fn map<'a, T, U, F>( - future: SendFuture::T<'a, 'ctx, Self::Future<T>, T>, + future: SendFuture::T<'a, Self::Future<T>, T>, func: F, - ) -> SendFuture::T<'a, 'ctx, Self::Future<U>, U> + ) -> SendFuture::T<'a, Self::Future<U>, U> where T: Send, U: Send, @@ -41,7 +38,7 @@ pub trait Effect<'ctx>: Send + 'static { #[inline] fn wrap_boxed<'a, F>( future: core::pin::Pin<Box<F>>, - ) -> SendFuture::T<'a, 'ctx, Self::Future<F::Output>, F::Output> + ) -> SendFuture::T<'a, Self::Future<F::Output>, F::Output> where F: core::future::Future + Send + 'a, <F as core::future::Future>::Output: Send, @@ -50,7 +47,7 @@ pub trait Effect<'ctx>: Send + 'static { } } -pub type Future<'a, 'ctx, T, E> = SendFuture::T<'a, 'ctx, <E as Effect<'ctx>>::Future<T>, T>; +pub type Future<'a, T, E> = SendFuture::T<'a, <E as Effect>::Future<T>, T>; pub struct Blocking<B = Spin> { _marker: PhantomData<fn() -> B>, @@ -88,7 +85,7 @@ impl BlockOn for Spin { #[inline] pub fn noop() -> Waker { - const VTABLE: &'static RawWakerVTable = &RawWakerVTable::new( + const VTABLE: &RawWakerVTable = &RawWakerVTable::new( // Cloning just returns a new no-op raw waker |_| RAW, // `wake` does nothing @@ -98,21 +95,22 @@ pub fn noop() -> Waker { // Dropping does nothing as we don't allocate anything |_| {}, ); - const RAW: RawWaker = RawWaker::new(ptr::null(), &VTABLE); + const RAW: RawWaker = RawWaker::new(ptr::null(), VTABLE); unsafe { Waker::from_raw(RAW) } } -higher_ranked_type! { - pub type ReadyFuture['ctx, Output]: (SendFuture)[Output] +bijective_higher_ranked_type! { + pub type ReadyFuture[][Output]: SendFuture[][Output] + for<'lt> (core::future::Ready<Output>) where { Output: Send, - } = for<'lt> core::future::Ready<Output> + } } -impl<'ctx, B: BlockOn> Effect<'ctx> for Blocking<B> { - type Future<T: Send> = ReadyFuture<'ctx, T>; +impl<B: BlockOn> Effect for Blocking<B> { + type Future<T: Send> = ReadyFuture<T>; - fn wrap<'a, F>(future: F) -> SendFuture::T<'a, 'ctx, Self::Future<F::Output>, F::Output> + fn wrap<'a, F>(future: F) -> SendFuture::T<'a, Self::Future<F::Output>, F::Output> where F: core::future::Future + Send + 'a, <F as core::future::Future>::Output: Send, @@ -120,14 +118,14 @@ impl<'ctx, B: BlockOn> Effect<'ctx> for Blocking<B> { core::future::ready(B::block_on(future)) } - fn ready<'a, T: Send>(value: T) -> SendFuture::T<'a, 'ctx, Self::Future<T>, T> { + fn ready<'a, T: Send>(value: T) -> SendFuture::T<'a, Self::Future<T>, T> { core::future::ready(value) } fn map<'a, T, U, F>( - future: SendFuture::T<'a, 'ctx, Self::Future<T>, T>, + future: SendFuture::T<'a, Self::Future<T>, T>, func: F, - ) -> SendFuture::T<'a, 'ctx, Self::Future<U>, U> + ) -> SendFuture::T<'a, Self::Future<U>, U> where T: Send, U: Send, @@ -160,21 +158,22 @@ mod sealed { } #[cfg(feature = "alloc")] -higher_ranked_type! { - pub type BoxFuture['ctx, Output]: (SendFuture)[Output] +bijective_higher_ranked_type! { + pub type BoxFuture[][Output]: SendFuture[][Output] + for<'lt> (sealed::BoxedFuture<'lt, Output>) where { Output: Send, - } = for<'lt> sealed::BoxedFuture<'lt, Output> + } } #[cfg(feature = "alloc")] pub enum Async {} #[cfg(feature = "alloc")] -impl<'ctx> Effect<'ctx> for Async { - type Future<T: Send> = BoxFuture<'ctx, T>; +impl Effect for Async { + type Future<T: Send> = BoxFuture<T>; - fn wrap<'a, F>(future: F) -> SendFuture::T<'a, 'ctx, Self::Future<F::Output>, F::Output> + fn wrap<'a, F>(future: F) -> SendFuture::T<'a, Self::Future<F::Output>, F::Output> where F: core::future::Future + Send + 'a, <F as core::future::Future>::Output: Send, @@ -182,14 +181,14 @@ impl<'ctx> Effect<'ctx> for Async { sealed::BoxedFuture::Box(Box::pin(future)) } - fn ready<'a, T: Send>(value: T) -> SendFuture::T<'a, 'ctx, Self::Future<T>, T> { + fn ready<'a, T: Send>(value: T) -> SendFuture::T<'a, Self::Future<T>, T> { sealed::BoxedFuture::Ready(core::future::ready(value)) } fn map<'a, T, U, F>( - future: SendFuture::T<'a, 'ctx, Self::Future<T>, T>, + future: SendFuture::T<'a, Self::Future<T>, T>, func: F, - ) -> SendFuture::T<'a, 'ctx, Self::Future<U>, U> + ) -> SendFuture::T<'a, Self::Future<U>, U> where T: Send, U: Send, @@ -206,7 +205,7 @@ impl<'ctx> Effect<'ctx> for Async { fn wrap_boxed<'a, F>( future: core::pin::Pin<Box<F>>, - ) -> SendFuture::T<'a, 'ctx, Self::Future<F::Output>, F::Output> + ) -> SendFuture::T<'a, Self::Future<F::Output>, F::Output> where F: core::future::Future + Send + 'a, <F as core::future::Future>::Output: Send, |