Created
January 26, 2015 09:03
-
-
Save dinfuehr/6e07ff2b3c0315dab7d6 to your computer and use it in GitHub Desktop.
Rust: cannot move out of borrowed content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Foo { | |
value: String | |
} | |
impl Foo { | |
fn test(&mut self) -> String { | |
let old = self.value; | |
self.value = "new".to_string(); | |
old | |
} | |
} | |
fn main() { | |
let mut foo = Foo { value: "old".to_string() }; | |
assert_eq!("old", foo.test()); | |
println!("foo = {}", foo.value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Error is thrown at line 7. How can I replace the value in the struct, but also retain the old value?