Guest User

Untitled

a guest
Apr 24th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.28 KB | None | 0 0
  1. use std::sync::Arc;
  2.  
  3. trait A {
  4. fn as_b(&self) -> Option<&B> { None }
  5. }
  6.  
  7. #[derive(Default)]
  8. struct B;
  9. impl A for B {
  10. fn as_b(&self) -> Option<&B> { Some(self) }
  11. }
  12.  
  13. fn main() {
  14. let obj: Arc<A> = Arc::new(B::default());
  15. let casted = obj.as_b();
  16. assert!(casted.is_some());
  17. }
Add Comment
Please, Sign In to add comment