Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. trait TraitA { type Item: ?Sized; }
  2.  
  3. trait TraitB<T> {
  4. fn hello(&self);
  5. }
  6.  
  7. impl<X: TraitA> TraitB<X> for X::Item {
  8. fn hello(&self) {
  9. println!("Hello for X::Item");
  10. }
  11. }
  12.  
  13. impl TraitB<()> for () {
  14. fn hello(&self) {
  15. println!("Hello for ()");
  16. }
  17. }
  18.  
  19. impl TraitA for () {
  20. type Item = dyn TraitB<()>;
  21. }
  22.  
  23. fn call_hello<T: ?Sized + TraitB<()>>(t: &T) {
  24. t.hello();
  25. }
  26.  
  27. fn main() {
  28. call_hello::<()>(&());
  29. call_hello::<dyn TraitB<()>>(&() as &dyn TraitB<()>);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement