pub struct Handle<Msg> { /* private fields */ }Expand description
A handle to send messages to or stop an Actor.
Implementations§
Source§impl<Msg> Handle<Msg>
impl<Msg> Handle<Msg>
Sourcepub fn restart(&self)
pub fn restart(&self)
Restarts the Actor by re-running Actor::init and Actor::sources. Does not wait for the actor to finish.
§Example
ⓘ
handle.restart();Sourcepub fn send<M: Into<Msg>>(&self, msg: M) -> bool
pub fn send<M: Into<Msg>>(&self, msg: M) -> bool
Sends a message to the Actor, returning true if the message was delivered
or false if the actor is no longer running.
Takes advantage of From<_> implementations on the message type.
§Example
ⓘ
// Given `#[derive(From)] enum Msg { Inc(u32) }`:
handle.send(Msg::Inc(1));
handle.send(1u32); // works via From<u32>Sourcepub async fn reqw<F, Req, Res>(
&self,
to_req: F,
req: Req,
) -> Result<Res, ReqErr>
pub async fn reqw<F, Req, Res>( &self, to_req: F, req: Req, ) -> Result<Res, ReqErr>
Like Handle::req, but uses a wrapper function to convert the Request into the message type.
Useful when the message variant can’t implement From<Request<Req, Res>>.
§Example
ⓘ
enum Msg {
GetCount(Request<(), u32>),
}
let count: u32 = handle.reqw(Msg::GetCount, ()).await?;Sourcepub async fn req_timeout<Req, Res>(
&self,
req: Req,
timeout: Duration,
) -> Result<Res, ReqErr>
pub async fn req_timeout<Req, Res>( &self, req: Req, timeout: Duration, ) -> Result<Res, ReqErr>
Like Handle::req, but fails with ReqErr::Timeout if no response within the given Duration.
§Example
ⓘ
let count: u32 = handle.req_timeout((), Duration::from_secs(1)).await?;Sourcepub async fn reqw_timeout<F, Req, Res>(
&self,
to_req: F,
req: Req,
timeout: Duration,
) -> Result<Res, ReqErr>
pub async fn reqw_timeout<F, Req, Res>( &self, to_req: F, req: Req, timeout: Duration, ) -> Result<Res, ReqErr>
Like Handle::reqw, but fails with ReqErr::Timeout if no response within the given Duration.
§Example
ⓘ
let count: u32 = handle.reqw_timeout(Msg::GetCount, (), Duration::from_secs(1)).await?;Trait Implementations§
Auto Trait Implementations§
impl<Msg> Freeze for Handle<Msg>
impl<Msg> RefUnwindSafe for Handle<Msg>
impl<Msg> Send for Handle<Msg>where
Msg: Send,
impl<Msg> Sync for Handle<Msg>where
Msg: Send,
impl<Msg> Unpin for Handle<Msg>
impl<Msg> UnsafeUnpin for Handle<Msg>
impl<Msg> UnwindSafe for Handle<Msg>
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
Mutably borrows from an owned value. Read more