@@ -33,6 +33,8 @@ use std::mem;
33
33
use std:: ops;
34
34
use std:: ptr;
35
35
use std:: slice;
36
+ #[ cfg( feature = "std" ) ]
37
+ use std:: io;
36
38
#[ cfg( feature="heapsizeof" ) ]
37
39
use std:: os:: raw:: c_void;
38
40
@@ -632,6 +634,26 @@ impl<A: Array> BorrowMut<[A::Item]> for SmallVec<A> {
632
634
}
633
635
}
634
636
637
+ #[ cfg( feature = "std" ) ]
638
+ impl < A : Array < Item = u8 > > io:: Write for SmallVec < A > {
639
+ #[ inline]
640
+ fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
641
+ self . extend_from_slice ( buf) ;
642
+ Ok ( buf. len ( ) )
643
+ }
644
+
645
+ #[ inline]
646
+ fn write_all ( & mut self , buf : & [ u8 ] ) -> io:: Result < ( ) > {
647
+ self . extend_from_slice ( buf) ;
648
+ Ok ( ( ) )
649
+ }
650
+
651
+ #[ inline]
652
+ fn flush ( & mut self ) -> io:: Result < ( ) > {
653
+ Ok ( ( ) )
654
+ }
655
+ }
656
+
635
657
impl < ' a , A : Array > From < & ' a [ A :: Item ] > for SmallVec < A > where A :: Item : Clone {
636
658
#[ inline]
637
659
fn from ( slice : & ' a [ A :: Item ] ) -> SmallVec < A > {
@@ -1436,4 +1458,21 @@ pub mod tests {
1436
1458
assert_eq ! ( & * small_vec, & [ 1 , 2 , 3 , 4 , 5 ] ) ;
1437
1459
drop ( small_vec) ;
1438
1460
}
1461
+
1462
+ #[ cfg( feature = "std" ) ]
1463
+ #[ test]
1464
+ fn test_write ( ) {
1465
+ use io:: Write ;
1466
+
1467
+ let data = [ 1 , 2 , 3 , 4 , 5 ] ;
1468
+
1469
+ let mut small_vec: SmallVec < [ u8 ; 2 ] > = SmallVec :: new ( ) ;
1470
+ let len = small_vec. write ( & data[ ..] ) . unwrap ( ) ;
1471
+ assert_eq ! ( len, 5 ) ;
1472
+ assert_eq ! ( small_vec. as_ref( ) , data. as_ref( ) ) ;
1473
+
1474
+ let mut small_vec: SmallVec < [ u8 ; 2 ] > = SmallVec :: new ( ) ;
1475
+ small_vec. write_all ( & data[ ..] ) . unwrap ( ) ;
1476
+ assert_eq ! ( small_vec. as_ref( ) , data. as_ref( ) ) ;
1477
+ }
1439
1478
}
0 commit comments