Skip to main content

RemoteMessage

Derive Macro RemoteMessage 

Source
#[derive(RemoteMessage)]
{
    // Attributes available to this derive:
    #[with_source]
}
Expand description

Helper to make messages sendable over network

§Example

#[derive(Message, Serialize, Deserialize, RemoteMessage)]
struct MyMessage {}

// ...

#[derive(RemoteActor)]
#[remote_messages(MyMessage)]
struct MyActor {}
// ...

§Background

In the previous example, the MyMessage struct gets extended the following way:

impl RemoteMessage for MyMessage {
    type Serializer = DefaultSerialization;
    const IDENTIFIER: &'static str = "MyMessage";

    fn get_serializer(&self) -> Box<Self::Serializer> {
        Box::new(DefaultSerialization {})
    }

    fn generate_serializer() -> Box<Self::Serializer> {
        Box::new(DefaultSerialization {})
    }

    fn set_source(&mut self, addr: Addr<NetworkInterface>) {

    }
}

§Options

If you add the derive attribute with_source, you have the possibility to set the source remote address on a predefined struct attribute. That attribute needs to have the following type: RemoteAddr

§Example

#[derive(Message, Serialize, Deserialize, RemoteMessage)]
#[with_source(source)]
struct MyMessage {
    source: RemoteAddr
}