Advertisement
Guest User

Untitled

a guest
Mar 28th, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. struct Bar;
  2.  
  3. trait Foo {
  4. fn foo(&self) {
  5. print!("Foo");
  6. }
  7. }
  8.  
  9. impl Foo for Bar {}
  10.  
  11. trait Print {
  12. type Kind;
  13. fn print(&Self::Kind);
  14. }
  15.  
  16. impl Print for Bar {
  17. type Kind = Bar;
  18. fn print(_: &Bar) {
  19. println!("Bar");
  20. }
  21. }
  22.  
  23. impl Print for Foo {
  24. type Kind = Bar;
  25. fn print(bar: &Bar) {
  26. bar.foo();
  27. Bar::print(bar);
  28. }
  29. }
  30.  
  31. fn main() {
  32. let b = Bar;
  33. Bar::print(&b); // prints: Bar
  34. Foo::print(&b); // prints: FooBar
  35. <Bar as Foo>::print(&b); // error
  36. }
  37.  
  38. <anon>:35:5: 35:25 error: unresolved name `Foo::print`
  39. <anon>:35 <Bar as Foo>::print(&b);
  40. ^~~~~~~~~~~~~~~~~~~~
  41. error: aborting due to previous error
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement