Skip to main content

BroadcastAs

Trait BroadcastAs 

Source
pub trait BroadcastAs<V> {
    // Required method
    fn to_broadcast(&self) -> V;
}
Expand description

Defines how to convert an actor’s value to its broadcast type.

A blanket implementation is provided for Clone types, broadcasting themselves. Implement this trait to broadcast a different type V from your actor type T, enabling:

  • Non-Clone types to participate in broadcasting
  • Clone types to broadcast a lightweight summary instead of the full value

§Examples

use actify::BroadcastAs;

struct HeavyState {
    data: Vec<u8>,
    summary: String,
}

#[derive(Clone, Debug)]
struct Summary(String);

impl BroadcastAs<Summary> for HeavyState {
    fn to_broadcast(&self) -> Summary {
        Summary(self.summary.clone())
    }
}

Required Methods§

Source

fn to_broadcast(&self) -> V

Implementors§

Source§

impl<T: Clone> BroadcastAs<T> for T