pub struct Response<T>(/* private fields */);Expand description
Concrete wrapper for protocol request-response methods that works in both
tasks (async) and threads (blocking) modes.
- Tasks mode: wraps a oneshot receiver;
.awaitreturnsResult<T, ActorError> - Threads mode: wraps a pre-computed result; use
.unwrap()/.expect()directly
Protocol methods return Response<T>:
#[protocol]
pub trait MyProtocol: Send + Sync {
fn query(&self) -> Response<String>;
}
// Tasks: actor.query().await.unwrap()
// Threads: actor.query().unwrap()Implementations§
Source§impl<T> Response<T>
impl<T> Response<T>
Sourcepub fn ready(result: Result<T, ActorError>) -> Self
pub fn ready(result: Result<T, ActorError>) -> Self
Create a Response from a pre-computed result.
Used by the threads runtime where the request blocks at call time and the result is immediately available.
Sourcepub fn unwrap(self) -> T
pub fn unwrap(self) -> T
Extract the value, panicking on error.
For ready (pre-computed) responses. Panics on pending responses —
use .await.unwrap() in async contexts instead.
Sourcepub fn expect(self, msg: &str) -> T
pub fn expect(self, msg: &str) -> T
Extract the value, panicking with a custom message on error.
Sourcepub fn is_ok(&self) -> bool
pub fn is_ok(&self) -> bool
Returns true if the response contains Ok.
Only meaningful for ready responses.
Returns false for pending (Receiver) or consumed (Done) states.
Source§impl<T: Send + 'static> Response<T>
impl<T: Send + 'static> Response<T>
Sourcepub fn from_with_timeout(
result: Result<Receiver<T>, ActorError>,
duration: Duration,
) -> Self
pub fn from_with_timeout( result: Result<Receiver<T>, ActorError>, duration: Duration, ) -> Self
Create a Response from a oneshot receiver with a timeout.
Used by tasks-mode protocol blanket impls. Returns
Err(ActorError::RequestTimeout) if the timeout expires.
Trait Implementations§
impl<T> Unpin for Response<T>
Auto Trait Implementations§
impl<T> Freeze for Response<T>where
T: Freeze,
impl<T> !RefUnwindSafe for Response<T>
impl<T> Send for Response<T>where
T: Send,
impl<T> !Sync for Response<T>
impl<T> UnsafeUnpin for Response<T>where
T: UnsafeUnpin,
impl<T> !UnwindSafe for Response<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_cancellation_token(
self,
cancellation_token: &CancellationToken,
) -> WithCancellationTokenFuture<'_, Self>where
Self: Sized,
fn with_cancellation_token(
self,
cancellation_token: &CancellationToken,
) -> WithCancellationTokenFuture<'_, Self>where
Self: Sized,
CancellationToken::run_until_cancelled,
but with the advantage that it is easier to write fluent call chains. Read moreSource§fn with_cancellation_token_owned(
self,
cancellation_token: CancellationToken,
) -> WithCancellationTokenFutureOwned<Self>where
Self: Sized,
fn with_cancellation_token_owned(
self,
cancellation_token: CancellationToken,
) -> WithCancellationTokenFutureOwned<Self>where
Self: Sized,
CancellationToken::run_until_cancelled_owned,
but with the advantage that it is easier to write fluent call chains. Read moreSource§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn map<U, F>(self, f: F) -> Map<Self, F>
fn map<U, F>(self, f: F) -> Map<Self, F>
Source§fn map_into<U>(self) -> MapInto<Self, U>
fn map_into<U>(self) -> MapInto<Self, U>
Source§fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
f. Read moreSource§fn left_future<B>(self) -> Either<Self, B>
fn left_future<B>(self) -> Either<Self, B>
Source§fn right_future<A>(self) -> Either<A, Self>
fn right_future<A>(self) -> Either<A, Self>
Source§fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
Source§fn flatten(self) -> Flatten<Self>
fn flatten(self) -> Flatten<Self>
Source§fn flatten_stream(self) -> FlattenStream<Self>
fn flatten_stream(self) -> FlattenStream<Self>
Source§fn fuse(self) -> Fuse<Self>where
Self: Sized,
fn fuse(self) -> Fuse<Self>where
Self: Sized,
poll will never again be called once it has
completed. This method can be used to turn any Future into a
FusedFuture. Read moreSource§fn inspect<F>(self, f: F) -> Inspect<Self, F>
fn inspect<F>(self, f: F) -> Inspect<Self, F>
Source§fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
Source§fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)where
Self: Sized,
fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)where
Self: Sized,
() on completion and sends
its output to another future on a separate task. Read moreSource§fn boxed<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a>>
fn boxed<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a>>
Source§fn boxed_local<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + 'a>>where
Self: Sized + 'a,
fn boxed_local<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + 'a>>where
Self: Sized + 'a,
Source§fn unit_error(self) -> UnitError<Self>where
Self: Sized,
fn unit_error(self) -> UnitError<Self>where
Self: Sized,
Future<Output = T> into a
TryFuture<Ok = T, Error = ()>.Source§fn never_error(self) -> NeverError<Self>where
Self: Sized,
fn never_error(self) -> NeverError<Self>where
Self: Sized,
Future<Output = T> into a
TryFuture<Ok = T, Error = Never>.