duplicate-flags.rs 475 B

123456789101112131415161718192021222324252627
  1. use intertrait::cast::*;
  2. use intertrait::*;
  3. use std::sync::Arc;
  4. #[cast_to([sync, sync] Greet)]
  5. struct Data;
  6. trait Source: CastFromSync {}
  7. trait Greet {
  8. fn greet(&self);
  9. }
  10. impl Greet for Data {
  11. fn greet(&self) {
  12. println!("Hello");
  13. }
  14. }
  15. impl Source for Data {}
  16. fn main() {
  17. let data = Arc::new(Data);
  18. let source: Arc<dyn Source> = data;
  19. let greet = source.cast::<dyn Greet>();
  20. greet.unwrap_or_else(|_| panic!("can't happen")).greet();
  21. }