Here’s an even better example:
use std::ops::Deref;
struct Foo {
value: i32,
}
struct Bar {
foo: Foo,
}
impl Deref for Bar {
type Target = Foo;
fn deref(&self) -> &Self::Target {
println!("Firing the nukes!");
&self.foo
}
}
fn main() {
let bar = Bar {
foo: Foo {
value: 10,
},
};
// Not a method call, but it still has side effects!
bar.value;
}