4 ms·
Self-reference is allowed, but it prevents moving. fn main() { // ok let mut inp = Input { words: vec![], phrase: String::from("foo bar") };
by edflsafoiewq 5y ago
Self-reference is allowed, but it prevents moving.
fn main() {
// ok
let mut inp = Input { words: vec![], phrase: String::from("foo bar") };
inp.words.push(&inp.phrase[0..3]);
inp.words.push(&inp.phrase[4..7]);
println!("{:?}", inp);
// this would give "cannot move out of `inp` because it is borrowed"
//let x = inp;
}
- emi2k01 5y agoIt also prevents borrowing `inp` or `inp.phrase` as mutable which makes it useless for most cases.