Producer

Trait Producer 

Source
pub trait Producer: Serialize + Deserialize {
    // Required method
    fn produce(&mut self) -> Box<dyn Actor>;

    // Provided method
    fn from_string(&self, content: String) -> Result<Box<dyn Producer>> { ... }
}
Expand description

§Producer

Implementation of an Actor trait involves two steps. First, implementation of the Actor trait itself. Once trait implentation is done - first step is complete. Making Actor instances available to system is job of the Producer. A Producer trait implemenation(each Producer implementation with an unique typetag name) is responsible for creating Actor instances at runtime. The Producer trait has the produce method - which gets invoked to hand out Actor instances during actor registration and restoration. So, the second step of Actor implemenation is to implement the Producer trait. While registering an Actor to the system - the define_actor! macro takes a serde serializable(https://github.com/serde-rs/serde) Producer instance and a name for the actor(string - which could be anything - a name for the actor). The Producer implemenation gets serialized and stored in the backing store.

Required Methods§

Source

fn produce(&mut self) -> Box<dyn Actor>

The method to be implemented to create Actor instances. The implementing type should be tagged as #[typetag::serde

https://github.com/dtolnay/typetag

Provided Methods§

Source

fn from_string(&self, content: String) -> Result<Box<dyn Producer>>

A method to rebuild a Producer implementation. Used internally by the system to generate Producers on demand from the backing store.

Trait Implementations§

Source§

impl<'de> Deserialize<'de> for Box<dyn Producer>

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'typetag> Serialize for dyn Producer + 'typetag

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<'typetag> Serialize for dyn Producer + Send + 'typetag

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<'typetag> Serialize for dyn Producer + Send + Sync + 'typetag

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<'typetag> Serialize for dyn Producer + Sync + 'typetag

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Implementors§