[][src]Trait kompact::prelude::ActorRaw

pub trait ActorRaw {
    type Message: MessageBounds;
    fn receive(&mut self, env: MsgEnvelope<Self::Message>) -> Handled;
}

The base trait for all actors

This trait handles raw message envelopes, without any unpacking or other convenient syntactic sugars.

Usually it's better to use the unwrapped functions in Actor, but this can be more efficient at times, for example when the content of the envelope isn't actually accessed in the component.

Example

use kompact::prelude::*;

#[derive(ComponentDefinition)]
struct RawActor {
   ctx: ComponentContext<Self>
}
ignore_lifecycle!(RawActor);
impl ActorRaw for RawActor {
    type Message = ();

    fn receive(&mut self, env: MsgEnvelope<Self::Message>) -> Handled {
        match env {
           MsgEnvelope::Typed(m) => info!(self.log(), "Got a local message: {:?}", m),
           MsgEnvelope::Net(nm) => info!(self.log(), "Got a network message: {:?}", nm),
        }
        Handled::Ok
    }
}

Associated Types

type Message: MessageBounds

The type of local messages the actor accepts

Loading content...

Required methods

fn receive(&mut self, env: MsgEnvelope<Self::Message>) -> Handled

Handle an incoming message

Incoming messages can either be local, in which case they are of type Self::Message (wrapped into a MsgEnvelope), or they are coming from the network, in which case they of type NetMessage (again wrapped into a MsgEnvelope).

Note

Remember that components usually run on a shared thread pool, so, just like for handle implementations, you shouldn't ever block in this method unless you know what you are doing.

Loading content...

Implementors

impl ActorRaw for TestComponent1[src]

type Message = Never

impl ActorRaw for TestComponent2[src]

type Message = Never

impl<A, M: MessageBounds> ActorRaw for A where
    A: Actor<Message = M>, 
[src]

type Message = M

Loading content...