Action

Struct Action 

Source
pub struct Action<H: Handler> { /* private fields */ }
Expand description

An Action<H> can be handled by a Handler using Action::handle_with. Actions can be created with the action! macro. Any Handler automatically implements HandleMessage<Action<H>>. Any Action<H> implements Protocol and Message automatically.

(See handler for an overview)

Implementations§

Source§

impl<H: Handler> Action<H>

Source

pub fn from_boxed_fn<F>(function: F) -> Self
where F: for<'a> FnOnce(&'a mut H, &'a mut H::State) -> BoxFuture<'a, Result<Flow<H>, H::Exception>> + Send + 'static,

Construct an action from a boxed FnOnce.

Normally an action is created with the action! macro.

Source

pub async fn handle_with( self, handler: &mut H, state: &mut H::State, ) -> Result<Flow<H>, H::Exception>
where H: Handler,

Handle the Action<H> with Handler H.

Trait Implementations§

Source§

impl<H> Debug for Action<H>
where H: Handler,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<H: Handler> FromPayload<Action<H>> for Action<H>

Source§

fn from_payload(payload: Self) -> Self
where Self: Sized,

Create the Protocol from the Message::Payload.
Source§

fn try_into_payload(self) -> Result<Self, Self>
where Self: Sized,

Attempt to convert the protocol into the Message::Payload of M.
Source§

impl<H: Handler> HandleMessage<Action<H>> for H

Source§

fn handle_msg<'life0, 'life1, 'async_trait>( &'life0 mut self, state: &'life1 mut Self::State, action: Action<H>, ) -> Pin<Box<dyn Future<Output = Result<Flow<H>, H::Exception>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

impl<H: Handler> HandledBy<H> for Action<H>

Source§

fn handle_with<'life0, 'life1, 'async_trait>( self, handler: &'life0 mut H, state: &'life1 mut <H as Handler>::State, ) -> Pin<Box<dyn Future<Output = HandlerResult<H>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

impl<H: Handler> Message for Action<H>

Source§

type Returned = <() as MessageDerive<Action<H>>>::Returned

The value that is returned when the message is sent.
Source§

type Payload = <() as MessageDerive<Action<H>>>::Payload

The payload of the message that is sent to the actor.
Source§

fn create(self) -> (Self::Payload, Self::Returned)

This is called before the message is sent.
Source§

fn cancel(payload: Self::Payload, returned: Self::Returned) -> Self

This is called if the message cannot be sent.
Source§

impl<H: Handler> Protocol for Action<H>

Source§

fn into_boxed_payload(self) -> BoxPayload

Take out the payload as a BoxPayload.
Source§

fn try_from_boxed_payload(payload: BoxPayload) -> Result<Self, BoxPayload>
where Self: Sized,

Attempt to create the Protocol from a message. Read more
Source§

fn accepts_msg(msg_id: &TypeId) -> bool
where Self: Sized,

Whether the Protocol accepts the type-id of a Message. Read more

Auto Trait Implementations§

§

impl<H> Freeze for Action<H>

§

impl<H> !RefUnwindSafe for Action<H>

§

impl<H> Send for Action<H>

§

impl<H> !Sync for Action<H>

§

impl<H> Unpin for Action<H>

§

impl<H> !UnwindSafe for Action<H>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.