Guest User

Untitled

a guest
Apr 20th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. trait Foo {
  2. fn fn1(&self) -> i32;
  3. }
  4.  
  5. struct FooImpl;
  6.  
  7. impl Foo for FooImpl {
  8. fn fn1(&self) -> i32 { 1 }
  9. }
  10.  
  11. trait FooExt : Foo {
  12. fn fn_ext(&self) -> i32 {
  13. self.fn1() + 1
  14. }
  15. }
  16.  
  17. impl<T: Foo> FooExt for T {}
  18.  
  19. impl<'a> Foo for &'a Foo {
  20. fn fn1(&self) -> i32 {
  21. (*self).fn1()
  22. }
  23. }
  24.  
  25. fn func(f: &Foo) {
  26. println!("func fn1: {}", f.fn1());
  27. println!("func fn_ext: {}", f.fn_ext());
  28. }
  29.  
  30. fn main() {
  31. let f = FooImpl;
  32. println!("fn1: {}", f.fn1());
  33. println!("fn_ext: {}", f.fn_ext());
  34. func(&f);
  35. }
Add Comment
Please, Sign In to add comment