Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. use std::sync::Arc;
  2. trait A: AsA {}
  3. trait B: A {}
  4.  
  5. trait AsA {
  6. fn as_a(&self) -> &A;
  7. }
  8.  
  9. impl<T: A> AsA for T {
  10. fn as_a(&self) -> &A {
  11. self
  12. }
  13. }
  14.  
  15. struct Y;
  16. impl A for Y {}
  17. impl B for Y {}
  18.  
  19. fn another(x: &dyn A){ }
  20.  
  21. fn something(x: Arc<dyn B>) {
  22. another(x.as_a());
  23. }
  24.  
  25. fn main() {
  26. let y = Y;
  27. something(Arc::new(y));
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement