Implement methods on a struct by defining an impl block for the struct and adding functions that take &self or &mut self as the first parameter.
struct Rectangle {
width: u32,
height: u32,
}
impl Rectangle {
fn area(&self) -> u32 {
self.width * self.height
}
}
The &self parameter allows the method to read the struct's data without taking ownership, while &mut self would allow modification.