• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // build-pass
2 #![allow(dead_code)]
3 #![allow(unused_variables)]
4 use std::any::TypeId;
5 use std::rc::Rc;
6 
7 type Fp<T> = Rc<T>;
8 
9 struct Engine;
10 
11 trait Component: 'static {}
12 impl Component for Engine {}
13 
14 trait Env {
get_component_type_id(&self, type_id: TypeId) -> Option<Fp<dyn Component>>15     fn get_component_type_id(&self, type_id: TypeId) -> Option<Fp<dyn Component>>;
16 }
17 
18 impl<'a> dyn Env + 'a {
get_component<T: Component>(&self) -> Option<Fp<T>>19     fn get_component<T: Component>(&self) -> Option<Fp<T>> {
20         let x = self.get_component_type_id(TypeId::of::<T>());
21         None
22     }
23 }
24 
25 trait Figment {
init(&mut self, env: &dyn Env)26     fn init(&mut self, env: &dyn Env);
27 }
28 
29 struct MyFigment;
30 
31 impl Figment for MyFigment {
init(&mut self, env: &dyn Env)32     fn init(&mut self, env: &dyn Env) {
33         let engine = env.get_component::<Engine>();
34     }
35 }
36 
main()37 fn main() {}
38