In the book Rust In the chapter "Method Syntax" there is an example of self-ownership:
struct Circle {
x: f64,
y: f64,
radius: f64,
}
impl Circle {
fn reference(&self) {
println!("taking self by reference!");
}
fn mutable_reference(&mut self) {
println!("taking self by mutable reference!");
}
fn takes_ownership(self) {
println!("taking ownership of self!");
}
}
What are some typical use cases requiring self-possession? Is this only when self is a value on the stack (where will it be copied)?
source
share