Slide 5
Slide 5 text
バイト列の読み込み
5
use std::io::{Read as _, Result};
fn main() -> Result<()> {
let mut bytes: &[u8] = &[0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc];
let mut buf = [0; 4];
bytes.read_exact(&mut buf)?;
println!("{:#x?}", buf); // [0x12, 0x34, 0x56, 0x78]
assert_eq!(bytes.len(), 2);
Ok(())
}