e2rcore/interface/
i_ele.rs1use std::any::Any;
2
3use interface::i_component;
5
6pub trait IObjImpl: IObjImplClone {
8 fn as_any( & self ) -> & Any;
9 fn update_components( & mut self, components: & mut Vec< Box< i_component::IComponent > > ) -> Result< (), & 'static str >;
10}
11
12pub trait IObjImplClone {
13 fn clone_box( & self ) -> Box< IObjImpl >;
14}
15
16impl< T > IObjImplClone for T where T: 'static + IObjImpl + Clone {
17 fn clone_box( & self ) -> Box< IObjImpl > {
18 Box::new( self.clone() )
19 }
20}
21
22impl Clone for Box< IObjImpl > {
23 fn clone( & self ) -> Box< IObjImpl > {
24 self.clone_box()
25 }
26}
27
28#[derive(Clone)]
30pub struct Ele {
31 pub _impl: Box< IObjImpl >,
32 pub _components: Vec< Box< i_component::IComponent > >,
33}
34
35impl Ele {
36 pub fn init< T >( c: T ) -> Ele where T : IObjImpl + 'static {
37 Ele {
38 _impl: Box::new(c),
39 _components: vec![],
40 }
41 }
42 pub fn update_components_from_impl( & mut self ) -> Result< (), & 'static str > {
43 self._components.clear();
44 self._impl.update_components( & mut self._components )
45 }
46 }
60
61