muzzman_lib/
common.rs

1use crate::{
2    events::Event,
3    prelude::{Ref, SessionError},
4    types::ID,
5};
6
7pub trait Common {
8    fn get_name(&self) -> Result<String, SessionError>;
9    fn set_name(&self, name: impl Into<String>) -> Result<(), SessionError>;
10
11    fn get_desc(&self) -> Result<String, SessionError>;
12    fn set_desc(&self, desc: impl Into<String>) -> Result<(), SessionError>;
13
14    fn notify(&self, event: Event) -> Result<(), SessionError>;
15
16    fn emit(&self, event: Event) -> Result<(), SessionError>;
17    fn subscribe(&self, _ref: ID) -> Result<(), SessionError>;
18    fn unsubscribe(&self, _ref: ID) -> Result<(), SessionError>;
19}
20
21impl Common for Ref {
22    fn get_name(&self) -> Result<String, crate::prelude::SessionError> {
23        match self {
24            Ref::Element(e) => e.get_name(),
25            Ref::Location(l) => l.get_name(),
26        }
27    }
28
29    fn set_name(&self, name: impl Into<String>) -> Result<(), crate::prelude::SessionError> {
30        match self {
31            Ref::Element(e) => e.set_name(name),
32            Ref::Location(l) => l.set_name(name),
33        }
34    }
35
36    fn get_desc(&self) -> Result<String, crate::prelude::SessionError> {
37        match self {
38            Ref::Element(e) => e.get_desc(),
39            Ref::Location(l) => l.get_desc(),
40        }
41    }
42
43    fn set_desc(&self, desc: impl Into<String>) -> Result<(), crate::prelude::SessionError> {
44        match self {
45            Ref::Element(e) => e.set_desc(desc),
46            Ref::Location(l) => l.set_desc(desc),
47        }
48    }
49
50    fn notify(&self, event: crate::events::Event) -> Result<(), crate::prelude::SessionError> {
51        match self {
52            Ref::Element(e) => e.notify(event),
53            Ref::Location(l) => l.notify(event),
54        }
55    }
56
57    fn emit(&self, event: Event) -> Result<(), SessionError> {
58        match self {
59            Ref::Element(e) => e.emit(event),
60            Ref::Location(l) => l.emit(event),
61        }
62    }
63
64    fn subscribe(&self, _ref: ID) -> Result<(), SessionError> {
65        match self {
66            Ref::Element(e) => e.subscribe(_ref),
67            Ref::Location(l) => l.subscribe(_ref),
68        }
69    }
70
71    fn unsubscribe(&self, _ref: ID) -> Result<(), SessionError> {
72        match self {
73            Ref::Element(e) => e.unsubscribe(_ref),
74            Ref::Location(l) => l.unsubscribe(_ref),
75        }
76    }
77}