File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -365,6 +365,18 @@ where
365
365
}
366
366
}
367
367
368
+ impl < N > fmt:: Write for Vec < u8 , N >
369
+ where
370
+ N : ArrayLength < u8 > ,
371
+ {
372
+ fn write_str ( & mut self , s : & str ) -> fmt:: Result {
373
+ match self . extend_from_slice ( s. as_bytes ( ) ) {
374
+ Ok ( ( ) ) => Ok ( ( ) ) ,
375
+ Err ( _) => Err ( fmt:: Error ) ,
376
+ }
377
+ }
378
+ }
379
+
368
380
impl < T , N > Drop for Vec < T , N >
369
381
where
370
382
N : ArrayLength < T > ,
@@ -645,6 +657,7 @@ where
645
657
#[ cfg( test) ]
646
658
mod tests {
647
659
use crate :: { consts:: * , Vec } ;
660
+ use core:: fmt:: Write ;
648
661
649
662
#[ test]
650
663
fn static_new ( ) {
@@ -911,4 +924,11 @@ mod tests {
911
924
v. resize_default ( 1 ) . unwrap ( ) ;
912
925
assert_eq ! ( v[ 0 ] , 0 ) ;
913
926
}
927
+
928
+ #[ test]
929
+ fn write ( ) {
930
+ let mut v: Vec < u8 , U4 > = Vec :: new ( ) ;
931
+ write ! ( v, "{:x}" , 1234 ) . unwrap ( ) ;
932
+ assert_eq ! ( & v[ ..] , b"4d2" )
933
+ }
914
934
}
You can’t perform that action at this time.
0 commit comments