pub struct Sender<T: Message> {
pub actor_id: ActorId,
/* private fields */
}Expand description
Sender of a specific message type
Like Caller<T>, Sender has a weak reference to the recipient of the message type, and so will not prevent an actor from stopping if all Addr's have been dropped elsewhere. This allows it to be used in send_later send_intervalactor functions, and not keep the actor alive indefinitely even after all references to it have been dropped (unlessctx.stop()` is called from within)
Fields§
§actor_id: ActorIdImplementations§
Source§impl<T: Message<Result = ()>> Sender<T>
impl<T: Message<Result = ()>> Sender<T>
Sourcepub fn send(&self, msg: T) -> Result<()>
pub fn send(&self, msg: T) -> Result<()>
Examples found in repository?
examples/subscriber.rs (line 164)
155 async fn handle(&mut self, _ctx: &mut Context<Self>, _msg: Broadcast) {
156 // Generate random number and broadcast that message to all subscribers
157 println!("Broadcasting");
158 // To avoid bringing in rand package for the sake of this example, we are hardcoding the "random" number
159 let random_int: i32 = 20;
160 let broadcast_message = RandomMessage(random_int);
161 let _: Vec<_> = self
162 .subscribers
163 .iter()
164 .map(|subscriber| subscriber.send(broadcast_message.clone()))
165 .collect();
166 }Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Sender<T>
impl<T> !RefUnwindSafe for Sender<T>
impl<T> Send for Sender<T>
impl<T> !Sync for Sender<T>
impl<T> Unpin for Sender<T>
impl<T> UnsafeUnpin for Sender<T>
impl<T> !UnwindSafe for Sender<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more