seal_rs/testkit/actors/
test_local_actor_ref.rs1use crate::common::tsafe::TSafe;
9use crate::actors::actor_cell::ActorCell;
10use crate::actors::abstract_actor_ref::{ActorRef, AbstractActorRef};
11use crate::actors::actor_path::ActorPath;
12use crate::actors::actor::Actor;
13use std::fmt;
14use std::any::Any;
15
16pub struct TestLocalActorRef {
17
18 pub cell: TSafe<ActorCell>,
20 pub path: TSafe<ActorPath>,
21 pub actor: TSafe<Actor + Send>
25}
26
27
28impl TestLocalActorRef {
29
30 pub fn new(cell: TSafe<ActorCell>, path: TSafe<ActorPath>) -> TestLocalActorRef {
32 let actor = cell.clone().lock().unwrap().actor.clone();
33 TestLocalActorRef {
34 cell,
35 path,
36 actor
37 }
38 }
39
40 fn inner_clone(self: &Self) -> Box<TestLocalActorRef> {
41 Box::new(TestLocalActorRef {
42 cell: self.cell.clone(),
43 path: self.path.clone(),
44 actor: self.actor.clone()
45 })
46 }
47}
48
49impl AbstractActorRef for TestLocalActorRef {
50
51 fn tell(self: &mut Self, msg: Box<Any + Send + 'static>, rself: Option<Box<AbstractActorRef + Send>>) {
53 let cell_cloned = self.cell.clone();
55 let path_cloned = self.path.clone();
56 let toref = Box::new(TestLocalActorRef::new(cell_cloned, path_cloned));
57 let mut cell = self.cell.lock().unwrap();
58 cell.send(&self.cell, msg, rself, toref)
59 }
61
62 fn path(self: &mut Self) -> ActorPath {
64 self.path.lock().unwrap().clone()
66 }
68
69 fn cell(self: &mut Self) -> TSafe<ActorCell> {
71 self.cell.clone()
73 }
75
76 fn clone(self: &Self) -> ActorRef {
78 self.inner_clone()
79 }
80
81 fn as_any(self: &Self) -> Box<Any> {
83 Box::new(self.inner_clone())
84 }
85}
86
87impl fmt::Display for TestLocalActorRef {
88 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
89 write!(f, "TestActorRef ({})", self.path.lock().unwrap())
90 }
91}
92
93impl PartialEq for TestLocalActorRef {
104 fn eq(&self, _other: &Self) -> bool {
105 true
106 }
108}
109
110impl Eq for TestLocalActorRef {}
111
112