Big-endian byte array conversion into i32: casting issues (Rust)
Trying to figure out why the following code breaks. I am trying to take a slice of a byte array and big-endian convert it into a u32: use std::iter::{Skip, Take}; use std::slice::Iter; const SLICE_SIZE: u32 = 4; const SLICE_OFFSET : u32 = 4; fn main() { let bytes: [u8; 8] = [0, 1, 2, 3, 4, 5, 6, 7]; let slice: Take<Skip<Iter<u8>>> = bytes.to_vec().iter() .skip(SLICE_OFFSET as usize) .take(SLICE_SIZE as usize); let x = u32::from_be_bytes(slice.cloned().collect()); } I get this error: `an array of type `[u8; 1]` cannot be built directly from an iterator [E0277] try collecting into a `Vec<u8>`, t
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.