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
pub use information::InformationProvider;
pub use std::any::Any;

pub trait GeneralInformationProvider {
    fn get_all_information(&self) -> Vec<&Any>;

    fn get_all_information_mut<'a>(&'a mut self) -> Vec<&'a mut Any>;

    fn get_information(&self, vertex_id: usize) -> &Any;

    fn get_information_mut<'a>(&'a mut self, vertex_id: usize) -> &'a mut Any;
}

impl <TBaseInformation> GeneralInformationProvider for InformationProvider<TBaseInformation>
    where TBaseInformation: Any {
    fn get_all_information(&self) -> Vec<&Any> {
        let self_as_base = self as &InformationProvider<TBaseInformation>;
        self_as_base
            .get_all_information()
            .into_iter()
            .map(|information| information as &Any)
            .collect()
    }

    fn get_all_information_mut<'a>(&'a mut self) -> Vec<&'a mut Any> {
        let self_as_base = self as &mut InformationProvider<TBaseInformation>;
        self_as_base
            .get_all_information_mut()
            .into_iter()
            .map(|information| information as &mut Any)
            .collect()
    }

    fn get_information(&self, vertex_id: usize) -> &Any {
        let self_as_base = self as &InformationProvider<TBaseInformation>;
        self_as_base.get_information(vertex_id) as &Any
    }

    fn get_information_mut<'a>(&'a mut self, vertex_id: usize) -> &'a mut Any {
        let self_as_base = self as &mut InformationProvider<TBaseInformation>;
        self_as_base.get_information_mut(vertex_id) as &mut Any
    }
}