mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-18 08:06:32 +00:00
27
kernel/crates/intertrait/tests/on-trait-impl.rs
Normal file
27
kernel/crates/intertrait/tests/on-trait-impl.rs
Normal file
@ -0,0 +1,27 @@
|
||||
use intertrait::cast::*;
|
||||
use intertrait::*;
|
||||
|
||||
struct Data;
|
||||
|
||||
trait Source: CastFrom {}
|
||||
|
||||
trait Greet {
|
||||
fn greet(&self);
|
||||
}
|
||||
|
||||
#[cast_to]
|
||||
impl Greet for Data {
|
||||
fn greet(&self) {
|
||||
println!("Hello");
|
||||
}
|
||||
}
|
||||
|
||||
impl Source for Data {}
|
||||
|
||||
#[test]
|
||||
fn test_cast_to_on_trait_impl() {
|
||||
let data = Data;
|
||||
let source: &dyn Source = &data;
|
||||
let greet = source.cast::<dyn Greet>();
|
||||
greet.unwrap().greet();
|
||||
}
|
Reference in New Issue
Block a user