1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use std::hash::{Hash, Hasher};
use std::fmt;
use std::sync::Arc;

pub type ActorId = u32;

/// An `ActorUri` represents the location of an actor, including the
/// path and actor system host.
/// 
/// Note: `host` is currently unused but will be utilized when
/// networking and clustering are introduced.
#[derive(Clone)]
pub struct ActorUri {
    pub uid: ActorId,
    pub name: Arc<String>,
    pub path: Arc<String>,
    pub host: Arc<String>,
}

impl ActorUri {
    pub fn temp() -> ActorUri {
        ActorUri {
            uid: 0,
            name: Arc::new(String::default()),
            path: Arc::new("/temp/temp_path".to_string()),
            host: Arc::new(String::default()),
        }
    }  
}

impl PartialEq for ActorUri {
    fn eq(&self, other: &ActorUri) -> bool {
        self.path == other.path
    }
}

impl Eq for ActorUri { }

impl Hash for ActorUri {
    fn hash<H: Hasher>(&self, state: &mut H) {
        self.path.hash(state);
    }
}

impl fmt::Display for ActorUri {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "ActorUri[{}]", self.path)
    }
}

impl fmt::Debug for ActorUri {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "ActorUri[{}://{}#{}]", self.host, self.path, self.uid)
    }
}