Diffstat (limited to 'src/effect.rs')
-rw-r--r--src/effect.rs68
1 files changed, 37 insertions, 31 deletions
diff --git a/src/effect.rs b/src/effect.rs
index cf8cbdd..920ee0e 100644
--- a/src/effect.rs
+++ b/src/effect.rs
@@ -60,6 +60,16 @@ pub struct Blocking<B = Spin> {
_marker: PhantomData<fn() -> B>,
}
+pub trait ReadyValue: core::future::Future {
+ fn value(self) -> Self::Output;
+}
+
+impl<T: Send> ReadyValue for core::future::Ready<T> {
+ fn value(self) -> Self::Output {
+ Spin::block_on(self)
+ }
+}
+
pub trait BlockOn: 'static {
fn block_on<F>(future: F) -> F::Output
where
@@ -106,36 +116,36 @@ pub fn noop() -> Waker {
unsafe { Waker::from_raw(RAW) }
}
-pub struct Ready<Output> {
- pub value: Option<Output>,
-}
-
-impl<Output> Ready<Output> {
- pub fn into_inner(self) -> Output {
- self.value.expect("`into_inner` called after completion")
- }
-}
-
-impl<Output> Unpin for Ready<Output> {}
-
-impl<Output> core::future::Future for Ready<Output> {
- type Output = Output;
-
- fn poll(mut self: core::pin::Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
- Poll::Ready(self.value.take().expect("`Ready` polled after completion"))
- }
-}
+// pub struct Ready<Output> {
+// pub value: Option<Output>,
+// }
+//
+// impl<Output> Ready<Output> {
+// pub fn into_inner(self) -> Output {
+// self.value.expect("`into_inner` called after completion")
+// }
+// }
+//
+// impl<Output> Unpin for Ready<Output> {}
+//
+// impl<Output> core::future::Future for Ready<Output> {
+// type Output = Output;
+//
+// fn poll(mut self: core::pin::Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
+// Poll::Ready(self.value.take().expect("`Ready` polled after completion"))
+// }
+// }
higher_ranked_type! {
impl SendFuture {
- impl['a, Output] type T['a, Output] for Ready<Output> =
- Ready<Output>
+ impl['a, Output] type T['a, Output] for core::future::Ready<Output> =
+ core::future::Ready<Output>
where {
Output: Send
};
- impl['a, Output] type HigherRanked['a, Output] for Ready<Output> =
- Ready<Output>
+ impl['a, Output] type HigherRanked['a, Output] for core::future::Ready<Output> =
+ core::future::Ready<Output>
where {
Output: Send
};
@@ -143,20 +153,18 @@ higher_ranked_type! {
}
impl<B: BlockOn> Effect for Blocking<B> {
- type Future<T: Send> = Ready<T>;
+ type Future<T: Send> = core::future::Ready<T>;
fn wrap<'a, F>(future: F) -> SendFuture::T<'a, F::Output, Self::Future<F::Output>>
where
F: core::future::Future + Send + 'a,
<F as core::future::Future>::Output: Send,
{
- Ready {
- value: Some(B::block_on(future)),
- }
+ core::future::ready(B::block_on(future))
}
fn ready<'a, T: Send>(value: T) -> SendFuture::T<'a, T, Self::Future<T>> {
- Ready { value: Some(value) }
+ core::future::ready(value)
}
fn map<'a, T, U, F>(
@@ -169,9 +177,7 @@ impl<B: BlockOn> Effect for Blocking<B> {
F: FnOnce(T) -> U + Send + 'a,
{
let value = B::block_on(future);
- Ready {
- value: Some(func(value)),
- }
+ core::future::ready(func(value))
}
}