Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
rust
fn score(hex: &[u8]) -> u8 {
let mut freq = HashMap::new();
for byte in hex {
match freq.get(&byte) {
Some(count) => freq.insert(byte, *count + 1),
None => freq.insert(byte, 1)
};
}
0
}
03-single-byte-xor-cipher.rs:30:28: 30:32 error: cannot borrow `freq` as mutable because it is also borrowed as immutable
03-single-byte-xor-cipher.rs:30 Some(count) => freq.insert(byte, *count + 1),
^~~~
03-single-byte-xor-cipher.rs:29:15: 29:19 note: previous borrow of `freq` occurs here; the immutable borrow prevents subsequent moves or mutable borrows of `freq` until the borrow ends
03-single-byte-xor-cipher.rs:29 match freq.get(&byte) {
^~~~
03-single-byte-xor-cipher.rs:32:10: 32:10 note: previous borrow ends here
03-single-byte-xor-cipher.rs:29 match freq.get(&byte) {
03-single-byte-xor-cipher.rs:30 Some(count) => freq.insert(byte, *count + 1),
03-single-byte-xor-cipher.rs:31 None => freq.insert(byte, 1)
03-single-byte-xor-cipher.rs:32 };
^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.