4
我試圖測試一些需要讀取器的代碼。我有一個功能:獲取字節數組的讀取器
fn next_byte<R: Read>(reader: &mut R) -> ...
我怎樣才能測試它的一些字節數組?該文件說,有一個impl<'a> Read for &'a [u8]
,這將意味着這應該工作:
next_byte(&mut ([0x00u8, 0x00][..]))
但不同意編譯:
the trait `std::io::Read` is not implemented for the type `[u8]`
爲什麼?我明確表示&mut
。
使用防鏽1.2.0