hexga_core/
accessor.rs

1
2// Todo: Make a Constructor trait ?
3
4pub trait Getter<T>
5{
6    fn get(&self) -> T;
7}
8
9pub trait Setter<T>
10{
11    fn set(&mut self, val: T) -> &mut Self;
12}
13
14
15pub trait GetterSetter<T> : Getter<T> + Setter<T>{}
16impl<S,T> GetterSetter<T> for S where S:Getter<T> +Setter<T>{}
17
18// Based on (GGEZ Has trait)[https://docs.rs/ggez/latest/ggez/context/trait.Has.html] 
19pub trait HasRef<T>
20{
21    fn retrive(&self) -> &T;
22}
23impl<T> HasRef<T> for T  { fn retrive(&self) -> &T { self } }
24
25// Based on (GGEZ HasMut trait)[https://docs.rs/ggez/latest/ggez/context/trait.HasMut.html] 
26pub trait HasMut<T>
27{
28    fn retrive_mut(&mut self) -> &mut T;
29}
30impl<T> HasMut<T> for T  { fn retrive_mut(&mut self) -> &mut T { self } }
31
32
33
34pub trait Has<T> : HasRef<T> + HasMut<T>{}
35impl<S,T> Has<T> for S where S:HasRef<T> +HasMut<T>{}