seal_rs/actors/
local_actor_ref.rs1use crate::common::tsafe::TSafe;
5use crate::actors::actor_cell::ActorCell;
6use crate::actors::abstract_actor_ref::{AbstractActorRef, ActorRef};
7use crate::actors::actor_path::ActorPath;
8use std::fmt;
9use std::any::Any;
10
11pub struct LocalActorRef {
12 pub cell: TSafe<ActorCell>,
13 pub path: TSafe<ActorPath>
14}
15
16impl LocalActorRef {
17
18 pub fn new(cell: TSafe<ActorCell>, path: TSafe<ActorPath>) -> LocalActorRef {
21 LocalActorRef {
22 cell,
23 path
24 }
25 }
26
27 fn inner_clone(self: &Self) -> Box<LocalActorRef> {
28 Box::new(LocalActorRef {
29 cell: self.cell.clone(),
30 path: self.path.clone(),
31 })
32 }
33}
34
35impl AbstractActorRef for LocalActorRef {
36
37 fn tell(self: &mut Self, msg: Box<Any + Send + 'static>, rself: Option<Box<AbstractActorRef + Send>>) {
50 let cell_cloned = self.cell.clone();
51 let path_cloned = self.path.clone();
52 let toref = Box::new(LocalActorRef::new(cell_cloned, path_cloned));
53 let mut cell = self.cell.lock().unwrap();
54 cell.send(&self.cell, msg, rself, toref) }
55
56 fn path(self: &mut Self) -> ActorPath {
58 self.path.lock().unwrap().clone()
59 }
60
61 fn cell(self: &mut Self) -> TSafe<ActorCell> {
62 self.cell.clone()
63 }
64
65 fn clone(self: &Self) -> ActorRef {
66 self.inner_clone()
67 }
68
69 fn as_any(self: &Self) -> Box<Any> {
70 Box::new(self.inner_clone())
71 }
72}
73
74impl fmt::Display for LocalActorRef {
75 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
76 write!(f, "ActorRef ({})", self.path.lock().unwrap())
77 }
78}
79
80impl PartialEq for LocalActorRef {
90 fn eq(&self, _other: &Self) -> bool {
91 true
92 }
94}
95
96impl Eq for LocalActorRef {}
97