fork download
  1. trait FooPow {
  2. fn pow(&self) -> i32;
  3. }
  4.  
  5. struct Foo(i32);
  6.  
  7. impl<'a> FooPow for &'a Foo {
  8. fn pow(&self) -> i32 {
  9. self.0 * self.0
  10. }
  11. }
  12.  
  13. /*impl<'a> FooPow for &'a mut Foo {
  14.   fn pow(&self) -> i32 {
  15.   self.0 * self.0
  16.   }
  17. }*/
  18.  
  19. fn test1(x: &Foo) {
  20. println!("{}", x.pow());
  21. }
  22.  
  23. fn test2(x: &mut Foo) {
  24. println!("{}", (&*x).pow());
  25. }
  26.  
  27. fn main() {
  28. test1(&Foo(42));
  29. test2(&mut Foo(42));
  30. }
Success #stdin #stdout 0s 4492KB
stdin
Standard input is empty
stdout
1764
1764