How do I compare an array slice with a vector in Rust? The code in question:
fn parse<R: io::Read>(reader: R, fixed: &[u8]) -> io::Result<bool> {
let mut buf = vec![0; fixed.len()];
match reader.read(&mut buf) {
Ok(n) => Ok(n == fixed.len() && fixed == &mut buf),
Err(e) => Err(e)
}
}
The error that I get:
error[E0277]: the trait bound `[u8]: std::cmp::PartialEq<std::vec::Vec<u8>>` is not satisfied
--> src/main.rs:32:47
|
32 | Ok(n) => Ok(n == fixed.len() && fixed == &mut buf),
| ^^ can't compare `[u8]` with `std::vec::Vec<u8>`
|
= help: the trait `std::cmp::PartialEq<std::vec::Vec<u8>>` is not implemented for `[u8]`
The answer must be simple but it is eluding me.