concision_core/traits/
setup.rs1use core::borrow::{Borrow, BorrowMut};
6
7pub trait Config {}
9
10pub trait Configuration<C>
13where
14 C: Config,
15 Self::Config: Borrow<C>,
16{
17 type Config: Config;
18
19 fn root(&self) -> &C;
20
21 fn set(&mut self, config: Self::Config);
22
23 fn set_root(&mut self, config: C);
24}
25
26pub trait Init {
27 fn init(self) -> Self;
28}
29
30pub trait InitInplace {
31 fn init(&mut self);
32}
33
34pub trait Setup {
35 type Config;
36
37 fn setup(&mut self, config: Self::Config);
38}
39
40pub trait Context<C>
41where
42 C: Config,
43{
44 type Cnf: Configuration<C>;
45
46 fn config(&self) -> Self::Cnf;
47}
48
49impl<C, D> Configuration<C> for D
54where
55 C: Config,
56 D: Config + BorrowMut<C>,
57{
58 type Config = D;
59
60 fn root(&self) -> &C {
61 self.borrow()
62 }
63
64 fn set(&mut self, config: Self::Config) {
65 *self = config;
66 }
67
68 fn set_root(&mut self, config: C) {
69 *self.borrow_mut() = config;
70 }
71}