【Rust】生存期-方法
作者:互联网
环境
- Rust 1.56.1
- VSCode 1.61.2
概念
参考:https://doc.rust-lang.org/stable/rust-by-example/scope/lifetime/methods.html
示例
main.rs
struct Owner(i32);
impl Owner {
fn add_one<'a>(&'a mut self) {
self.0 += 1;
}
fn print<'a>(&'a self) {
println!("`print`: {}", self.0);
}
}
fn main() {
let mut owner = Owner(18);
owner.add_one();
owner.print();
}
总结
了解了 Rust 中的方法的生存期参数的标注。
附录
标签:mut,print,生存期,Rust,owner,方法,Owner,fn 来源: https://www.cnblogs.com/jiangbo44/p/15703797.html