[][src]Struct actix_mock_helper::MockActorSequence

pub struct MockActorSequence { /* fields omitted */ }

A mock for a sequence of messages sent to the actor Example:

struct FakeActor;
impl Actor for FakeActor {
    type Context = actix::Context<Self>;
}
struct Msg1;
struct Msg2;
impl Message for Msg1 {
  type Result = i32;
}
impl Message for Msg2 {
  type Result = bool;
}
#[actix_rt::main]
async fn main() {
  let mock_actor = MockActorSequence::new()
    .msg(|_m: &Msg1| 5) // you can access the message sent.
    .msg::<Msg2, _>(|_m| true) // alternate syntax to specify the message type
    .build::<FakeActor>();
  assert_eq!(mock_actor.send(Msg1).await.unwrap(), 5);
  assert_eq!(mock_actor.send(Msg2).await.unwrap(), true);
}

Implementations

impl MockActorSequence[src]

pub fn new() -> Self[src]

pub fn msg<Msg: Message, Cb>(self, cb: Cb) -> Self where
    Msg: 'static,
    Cb: FnMut(&Msg) -> Msg::Result,
    Cb: 'static, 
[src]

Add another message to be expected, and return the result of the callback. The type of the message is checked at runtime against the expectation, and the message itself is passed to the callback so that it can be used to build the result

pub fn build<A: Actor>(self) -> Addr<Mocker<A>>[src]

Fnalize the sequence and build the actor. Returns an Addr to the actor. Must provide the actor type

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,