xref: /DragonOS/kernel/crates/intertrait/tests/on-struct.rs (revision bd70d2d1f490aabd570a5301b858bd5eb04149fa)
1 use intertrait::cast::*;
2 use intertrait::*;
3 
4 #[cast_to(Greet)]
5 struct Data;
6 
7 trait Source: CastFrom {}
8 
9 trait Greet {
greet(&self)10     fn greet(&self);
11 }
12 
13 impl Greet for Data {
greet(&self)14     fn greet(&self) {
15         println!("Hello");
16     }
17 }
18 
19 impl Source for Data {}
20 
21 #[test]
test_cast_to_on_struct()22 fn test_cast_to_on_struct() {
23     let data = Data;
24     let source: &dyn Source = &data;
25     let greet = source.cast::<dyn Greet>();
26     greet.unwrap().greet();
27 }
28