Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.29 KB | None | 0 0
  1. use std::ops::Deref;
  2.  
  3. pub trait Trait1 { }
  4. pub trait Trait2 { }
  5.  
  6. impl<T> Trait2 for T where T: Trait1 { }
  7.  
  8. fn foo<D, T>(obj: D)
  9. where
  10. D: Deref<Target=T>,
  11. T: Trait2 + ?Sized,
  12. {
  13. }
  14.  
  15. fn main() {
  16. let a: Option<Box<dyn Trait1>> = None;
  17. if let Some(obj) = a {
  18. foo(obj);
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement