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
/*
    Appellation: states <module>
    Contrib: FL03 <jo3mccain@icloud.com>
    Description: ... Summary ...
*/
pub use self::{specs::*, state::*};

pub(crate) mod state;

pub(crate) mod specs {
    use crate::messages::Message;
    use std::sync::Arc;

    pub trait StatePack: Default + ToString {
        fn by_ref(&self) -> &Self {
            self
        }
        fn by_ref_mut(&mut self) -> &mut Self {
            self
        }
    }

    pub trait Stateful<S: StatePack>: Clone + Default {
        type Data;
        fn by_ref(&self) -> Self {
            self.clone()
        }
        fn by_ref_mut(&mut self) -> Self {
            self.clone()
        }
        fn by_arc(self: Arc<Self>) -> Arc<Self> {
            self
        }
        fn message(self) -> Message<Self::Data>;
        fn state(self) -> S;
        fn timestamp(self) -> i64;
    }

    pub trait StatefulExt<S: StatePack>: Stateful<S> {
        fn now() -> i64 {
            chrono::Utc::now().timestamp()
        }
        fn update_state(&mut self, msg: Option<Message<Self::Data>>, state: S) -> &Self;
    }
}