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
use std::{cell::RefCell, rc::Rc};

use super::{
    options::Opt,
    structs::{SConfig, SRole, STask},
};
pub type RcRefCell<T> = Rc<RefCell<T>>;

pub type SConfigWrapper = RcRefCell<SConfig>;
pub type SRoleWrapper = RcRefCell<SRole>;
pub type STaskWrapper = RcRefCell<STask>;
pub type OptWrapper = Option<RcRefCell<Opt>>;

pub trait DefaultWrapper {
    fn default() -> Self;
}

impl DefaultWrapper for SConfigWrapper {
    fn default() -> Self {
        Rc::new(RefCell::new(SConfig::default()))
    }
}

impl DefaultWrapper for SRoleWrapper {
    fn default() -> Self {
        Rc::new(RefCell::new(SRole::default()))
    }
}

impl DefaultWrapper for STaskWrapper {
    fn default() -> Self {
        Rc::new(RefCell::new(STask::default()))
    }
}

impl DefaultWrapper for OptWrapper {
    fn default() -> Self {
        None
    }
}