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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use crate::{events::Event, prelude::SessionError, types::Ref};

pub trait Common {
    fn get_name(&self) -> Result<String, SessionError>;
    fn set_name(&self, name: impl Into<String>) -> Result<(), SessionError>;

    fn get_desc(&self) -> Result<String, SessionError>;
    fn set_desc(&self, desc: impl Into<String>) -> Result<(), SessionError>;

    fn notify(&self, event: Event) -> Result<(), SessionError>;

    fn emit(&self, event: Event) -> Result<(), SessionError>;
    fn subscribe(&self, _ref: Ref) -> Result<(), SessionError>;
    fn unsubscribe(&self, _ref: Ref) -> Result<(), SessionError>;
}

impl Common for Ref {
    fn get_name(&self) -> Result<String, crate::prelude::SessionError> {
        match self {
            Ref::Element(e) => e.get_name(),
            Ref::Location(l) => l.get_name(),
        }
    }

    fn set_name(&self, name: impl Into<String>) -> Result<(), crate::prelude::SessionError> {
        match self {
            Ref::Element(e) => e.set_name(name),
            Ref::Location(l) => l.set_name(name),
        }
    }

    fn get_desc(&self) -> Result<String, crate::prelude::SessionError> {
        match self {
            Ref::Element(e) => e.get_desc(),
            Ref::Location(l) => l.get_desc(),
        }
    }

    fn set_desc(&self, desc: impl Into<String>) -> Result<(), crate::prelude::SessionError> {
        match self {
            Ref::Element(e) => e.set_desc(desc),
            Ref::Location(l) => l.set_desc(desc),
        }
    }

    fn notify(&self, event: crate::events::Event) -> Result<(), crate::prelude::SessionError> {
        match self {
            Ref::Element(e) => e.notify(event),
            Ref::Location(l) => l.notify(event),
        }
    }

    fn emit(&self, event: Event) -> Result<(), SessionError> {
        match self {
            Ref::Element(e) => e.emit(event),
            Ref::Location(l) => l.emit(event),
        }
    }

    fn subscribe(&self, _ref: Ref) -> Result<(), SessionError> {
        match self {
            Ref::Element(e) => e.subscribe(_ref),
            Ref::Location(l) => l.subscribe(_ref),
        }
    }

    fn unsubscribe(&self, _ref: Ref) -> Result<(), SessionError> {
        match self {
            Ref::Element(e) => e.unsubscribe(_ref),
            Ref::Location(l) => l.unsubscribe(_ref),
        }
    }
}