Associated functions
Add functions to structs via impl
- Associated functions must accept
&mut self
or&self
as first parameter- also possible:
Box<Self>, Rc<Self>, Arc<Self>
- also possible:
self
does not have to be passed when calling the function
Example
pub struct Person {
name: String;
}
impl Person {
pub fn walk(&mut self) {
println("{} is walking", self.name)
}
}