1 #[test]
read_exact()2 fn read_exact() {
3 use futures::executor::block_on;
4 use futures::io::AsyncReadExt;
5
6 let mut reader: &[u8] = &[1, 2, 3, 4, 5];
7 let mut out = [0u8; 3];
8
9 let res = block_on(reader.read_exact(&mut out)); // read 3 bytes out
10 assert!(res.is_ok());
11 assert_eq!(out, [1,2,3]);
12 assert_eq!(reader.len(), 2);
13
14 let res = block_on(reader.read_exact(&mut out)); // read another 3 bytes, but only 2 bytes left
15 assert!(res.is_err());
16 assert_eq!(reader.len(), 0);
17 }
18