Skip to content

Instantly share code, notes, and snippets.

@caipre
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caipre/1accece51d2d2b3d9744 to your computer and use it in GitHub Desktop.
Save caipre/1accece51d2d2b3d9744 to your computer and use it in GitHub Desktop.
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