xref: /DragonOS/kernel/crates/intertrait/tests/on-trait-impl.rs (revision bd70d2d1f490aabd570a5301b858bd5eb04149fa)
1 use intertrait::cast::*;
2 use intertrait::*;
3 
4 struct Data;
5 
6 trait Source: CastFrom {}
7 
8 trait Greet {
greet(&self)9     fn greet(&self);
10 }
11 
12 #[cast_to]
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_trait_impl()22 fn test_cast_to_on_trait_impl() {
23     let data = Data;
24     let source: &dyn Source = &data;
25     let greet = source.cast::<dyn Greet>();
26     greet.unwrap().greet();
27 }
28