In Rust, methods are defined within impl blocks. The &self in the area method is similar to this in other languages, but in Rust, you explicitly specify whether you’re borrowing (&self), mutably borrowing (&mut self), or taking ownership (self).
Rust doesn’t require explicit dereferencing when calling methods on references. This is known as “auto-dereferencing” or “deref coercion”.
Note that in this Rust version, we can’t call perim() on a reference because it takes ownership of self. This demonstrates Rust’s ownership system, which prevents use-after-move errors at compile time.
Next, we’ll look at Rust’s mechanism for defining abstract behavior: traits.