mirror of
https://github.com/ahgamut/rust-ape-example.git
synced 2024-11-25 01:01:01 +00:00
24 lines
371 B
Rust
24 lines
371 B
Rust
// ./src/scope/lifetime/methods.md
|
|
|
|
|
|
struct Owner(i32);
|
|
|
|
impl Owner {
|
|
// Annotate lifetimes as in a standalone function.
|
|
fn add_one<'a>(&'a mut self) { self.0 += 1; }
|
|
fn print<'a>(&'a self) {
|
|
println!("`print`: {}", self.0);
|
|
}
|
|
}
|
|
|
|
fn part0() {
|
|
let mut owner = Owner(18);
|
|
|
|
owner.add_one();
|
|
owner.print();
|
|
}
|
|
|
|
pub fn main() {
|
|
part0();
|
|
}
|
|
|