SHARE
TWEET

Untitled

a guest Sep 17th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top