Guest User

Untitled

a guest
Jul 23rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. trait Bar {
  2. fn required(&self);
  3. fn provided(&self) {
  4. println!("I'm a boring default...");
  5. }
  6. }
  7.  
  8. impl Bar for u32 {
  9. fn required(&self) {
  10. println!("u32 yeah yeah");
  11. }
  12. fn provided(&self) {
  13. println!("I'm a uuuuuu32!!");
  14. }
  15. }
  16.  
  17. // The impl would be generated
  18. impl<T: Bar> Bar for Box<T> {
  19. fn required(&self) {
  20. (**self).required()
  21. }
  22.  
  23. // Remove this to see difference
  24. fn provided(&self) {
  25. (**self).provided()
  26. }
  27. }
  28.  
  29.  
  30. fn main() {
  31. Bar::provided(&0);
  32. Bar::provided(&Box::new(0));
  33. }
Add Comment
Please, Sign In to add comment