You are trying to call next_byte::<[u8]> , but [u8] does not implement Read . [u8] and &'a [u8] not of the same type! [u8] is the type of the non-standard array, and &'a [u8] is the slice.
When you use the Read implementation on a slice, it must mutate the slice so that the next read resumes from the end of the previous read. So you need to pass volatile borrowing to fragment.
Here is a simple working example:
use std::io::Read; fn next_byte<R: Read>(reader: &mut R) { let mut b = [0]; reader.read(&mut b); println!("{} ", b[0]); } fn main() { let mut v = &[1u8, 2, 3] as &[u8]; next_byte(&mut v); next_byte(&mut v); next_byte(&mut v); }
source share