File tree 2 files changed +21
-0
lines changed
2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -594,3 +594,17 @@ where
594
594
Ok ( v)
595
595
}
596
596
}
597
+
598
+ impl < ' a , A > TryFrom < fmt:: Arguments < ' a > > for ArrayString < A >
599
+ where
600
+ A : Array < Item = u8 > + Copy
601
+ {
602
+ type Error = CapacityError < fmt:: Error > ;
603
+
604
+ fn try_from ( f : fmt:: Arguments < ' a > ) -> Result < Self , Self :: Error > {
605
+ use fmt:: Write ;
606
+ let mut v = Self :: new ( ) ;
607
+ v. write_fmt ( f) . map_err ( |e| CapacityError :: new ( e) ) ?;
608
+ Ok ( v)
609
+ }
610
+ }
Original file line number Diff line number Diff line change @@ -686,3 +686,10 @@ fn test_extend_zst() {
686
686
assert_eq ! ( & array[ ..] , & [ Z ; 5 ] ) ;
687
687
assert_eq ! ( array. len( ) , 5 ) ;
688
688
}
689
+
690
+ #[ test]
691
+ fn test_try_from_argument ( ) {
692
+ use core:: convert:: TryFrom ;
693
+ let v = ArrayString :: < [ u8 ; 16 ] > :: try_from ( format_args ! ( "Hello {}" , 123 ) ) . unwrap ( ) ;
694
+ assert_eq ! ( & v, "Hello 123" ) ;
695
+ }
You can’t perform that action at this time.
0 commit comments