Let's assume I have the following slice (code does not compile):
struct Data {
data: Vec<u8>
}
impl Data {
pub fn parse_ipv4(&self) -> Ipv4Addr {
let octets: [u8; 4] = self.data[2..6]; // this does not compile
Some(Ipv4Addr::from(octets));
}
}
The problem is that the compiler cannot infer the usize
of the slice of data
, so how do I explicitly tell it the length of the new array?