Closed
Description
struct Sheep {
message: String
}
impl Sheep {
fn talk(self) {
println!("{}", self.message);
}
}
fn main()
{
let sheep = &Sheep { message: "Määh".into() };
sheep.talk();
}
Errors:
Compiling playground v0.0.1 (/playground)
error[E0507]: cannot move out of borrowed content
--> src/main.rs:14:5
|
14 | sheep.talk();
| ^^^^^ cannot move out of borrowed content
error[E0507]: cannot move out of `*sheep` which is behind a `&` reference
--> src/main.rs:14:5
|
13 | let sheep = &Sheep { message: "Määh".into() };
| --------------------------------- help: consider changing this to be a mutable reference: `&mut Sheep { message: "Määh".into() }`
14 | sheep.talk();
| ^^^^^
| |
| cannot move out of `*sheep` which is behind a `&` reference
| `sheep` is a `&` reference, so the data it refers to cannot be moved
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0507`.
error: Could not compile `playground`.
To learn more, run the command again with --verbose.