trait FooPow {
}
struct Foo(i32);
impl<'a> FooPow for &'a Foo {
self.0 * self.0
}
}
/*impl<'a> FooPow for &'a mut Foo {
fn pow(&self) -> i32 {
self.0 * self.0
}
}*/
fn test1(x: &Foo) {
}
fn test2(x: &mut Foo) {
println
!("{}", (&*x
).
pow());}
fn main() {
test1(&Foo(42));
test2(&mut Foo(42));
}
dHJhaXQgRm9vUG93IHsKICAgIGZuIHBvdygmc2VsZikgLT4gaTMyOwp9CgpzdHJ1Y3QgRm9vKGkzMik7CgppbXBsPCdhPiBGb29Qb3cgZm9yICYnYSBGb28gewogICAgZm4gcG93KCZzZWxmKSAtPiBpMzIgewogICAgICAgIHNlbGYuMCAqIHNlbGYuMAogICAgfQp9CgovKmltcGw8J2E+IEZvb1BvdyBmb3IgJidhIG11dCBGb28gewogICAgZm4gcG93KCZzZWxmKSAtPiBpMzIgewogICAgICAgIHNlbGYuMCAqIHNlbGYuMAogICAgfQp9Ki8KCmZuIHRlc3QxKHg6ICZGb28pIHsKICAgIHByaW50bG4hKCJ7fSIsIHgucG93KCkpOwp9CgpmbiB0ZXN0Mih4OiAmbXV0IEZvbykgewogICAgcHJpbnRsbiEoInt9IiwgKCYqeCkucG93KCkpOwp9CgpmbiBtYWluKCkgewogICAgdGVzdDEoJkZvbyg0MikpOwogICAgdGVzdDIoJm11dCBGb28oNDIpKTsKfQ==