@@ -2083,7 +2083,7 @@ fn quicksort_unstable() {
20832083mod read_tests {
20842084 use core:: mem:: MaybeUninit ;
20852085 use staticvec:: * ;
2086- use std:: io:: { self , BufRead , Read } ;
2086+ use std:: io:: { self , BorrowedBuf , BufRead , Read } ;
20872087
20882088 // We provide custom implementations of most `Read` methods; test those impls
20892089 #[ test]
@@ -2174,6 +2174,38 @@ mod read_tests {
21742174 assert_eq ! ( ints2, [ 10 , 11 , 12 ] ) ;
21752175 }
21762176
2177+ #[ test]
2178+ fn read_buf ( ) {
2179+ let inner: & [ u8 ] = & [ 5 , 6 , 7 , 0 , 1 , 2 , 3 , 4 ] ;
2180+ let mut reader = StaticVec :: < u8 , 8 > :: from ( inner) ;
2181+ let buf: & mut [ _ ] = & mut [ MaybeUninit :: uninit ( ) ; 3 ] ;
2182+ let mut buf: BorrowedBuf < ' _ > = buf. into ( ) ;
2183+ reader. read_buf ( buf. unfilled ( ) ) . unwrap ( ) ;
2184+ assert_eq ! ( buf. filled( ) , [ 5 , 6 , 7 ] ) ;
2185+ assert_eq ! ( reader, [ 0 , 1 , 2 , 3 , 4 ] ) ;
2186+ let buf: & mut [ _ ] = & mut [ MaybeUninit :: uninit ( ) ; 2 ] ;
2187+ let mut buf: BorrowedBuf < ' _ > = buf. into ( ) ;
2188+ reader. read_buf ( buf. unfilled ( ) ) . unwrap ( ) ;
2189+ assert_eq ! ( buf. filled( ) , [ 0 , 1 ] ) ;
2190+ assert_eq ! ( reader, [ 2 , 3 , 4 ] ) ;
2191+ let buf: & mut [ _ ] = & mut [ MaybeUninit :: uninit ( ) ; 1 ] ;
2192+ let mut buf: BorrowedBuf < ' _ > = buf. into ( ) ;
2193+ reader. read_buf ( buf. unfilled ( ) ) . unwrap ( ) ;
2194+ assert_eq ! ( buf. filled( ) , [ 2 ] ) ;
2195+ assert_eq ! ( reader, [ 3 , 4 ] ) ;
2196+ let buf: & mut [ _ ] = & mut [ MaybeUninit :: uninit ( ) ; 3 ] ;
2197+ let mut buf: BorrowedBuf < ' _ > = buf. into ( ) ;
2198+ reader. read_buf ( buf. unfilled ( ) ) . unwrap ( ) ;
2199+ assert_eq ! ( buf. filled( ) , [ 3 , 4 ] ) ;
2200+ assert_eq ! ( reader, [ ] ) ;
2201+ reader. read_buf ( buf. unfilled ( ) ) . unwrap ( ) ;
2202+ assert_eq ! ( buf. filled( ) , [ 3 , 4 ] ) ;
2203+ assert_eq ! ( reader, [ ] ) ;
2204+ buf. clear ( ) ;
2205+ reader. read_buf ( buf. unfilled ( ) ) . unwrap ( ) ;
2206+ assert ! ( buf. filled( ) . is_empty( ) ) ;
2207+ }
2208+
21772209 #[ test]
21782210 fn bufread ( ) {
21792211 let mut cursor = StaticVec :: < u8 , 7 > :: from ( "foo\n bar" . as_bytes ( ) ) ;
0 commit comments