1use futures::executor::block_on;
2use futures::io::AsyncReadExt;
3
4#[test]
5fn read_exact() {
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