mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 08:44:35 +00:00
29 lines
498 B
Rust
29 lines
498 B
Rust
struct Dog {
|
|
cats_chased: usize,
|
|
}
|
|
|
|
impl Dog {
|
|
pub fn chase_cat(&mut self) {
|
|
let p: &'static mut usize = &mut self.cats_chased;
|
|
//~^ ERROR lifetime may not live long enough
|
|
*p += 1;
|
|
}
|
|
|
|
pub fn chase_cat_2(&mut self) {
|
|
let p: &mut usize = &mut self.cats_chased;
|
|
*p += 1;
|
|
}
|
|
}
|
|
|
|
fn dog() -> Dog {
|
|
Dog {
|
|
cats_chased: 0
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
let mut d = dog();
|
|
d.chase_cat();
|
|
println!("cats_chased: {}", d.cats_chased);
|
|
}
|