Last active
August 29, 2015 14:12
-
-
Save jaapz/dd46774f98029999128d to your computer and use it in GitHub Desktop.
Why does this happen?
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 Record { | |
name: String, | |
message: String, | |
} | |
// Let's say `record` is an instance of Record, with strings in name and message. | |
// This will work correctly: | |
let message = | |
if some_condition { | |
record.name.as_slice() | |
} else { | |
record.message.as_slice() | |
}; | |
// This will break, saying error: cannot move out of dereference of `&`-pointer. | |
let message = | |
if some_condition { | |
record.name | |
} else { | |
record.message | |
}; | |
// This is how i create the records | |
let mut records: Vec<Record> = vec![]; | |
for record in reader.decode() { | |
let record: Record = record.unwrap(); | |
records.push(record); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment