@@ -3,17 +3,30 @@ use crate::{
33 vec:: { VecInner , VecStorage } ,
44 CapacityError ,
55} ;
6+ use ufmt:: uDisplay;
67use ufmt_write:: uWrite;
78
9+ impl < S : StringStorage + ?Sized > uDisplay for StringInner < S > {
10+ #[ inline]
11+ fn fmt < W > ( & self , f : & mut ufmt:: Formatter < ' _ , W > ) -> Result < ( ) , W :: Error >
12+ where
13+ W : uWrite + ?Sized ,
14+ {
15+ f. write_str ( & self . as_str ( ) )
16+ }
17+ }
18+
819impl < S : StringStorage + ?Sized > uWrite for StringInner < S > {
920 type Error = CapacityError ;
21+ #[ inline]
1022 fn write_str ( & mut self , s : & str ) -> Result < ( ) , Self :: Error > {
1123 self . push_str ( s)
1224 }
1325}
1426
1527impl < S : VecStorage < u8 > + ?Sized > uWrite for VecInner < u8 , S > {
1628 type Error = CapacityError ;
29+ #[ inline]
1730 fn write_str ( & mut self , s : & str ) -> Result < ( ) , Self :: Error > {
1831 self . extend_from_slice ( s. as_bytes ( ) )
1932 }
@@ -32,7 +45,16 @@ mod tests {
3245 }
3346
3447 #[ test]
35- fn test_string ( ) {
48+ fn test_udisplay_string ( ) {
49+ let str_a = String :: < 32 > :: try_from ( "world" ) . unwrap ( ) ;
50+ let mut str_b = String :: < 32 > :: new ( ) ;
51+ uwrite ! ( str_b, "Hello {}!" , str_a) . unwrap ( ) ;
52+
53+ assert_eq ! ( str_b, "Hello world!" ) ;
54+ }
55+
56+ #[ test]
57+ fn test_uwrite_string ( ) {
3658 let a = 123 ;
3759 let b = Pair { x : 0 , y : 1234 } ;
3860
@@ -43,14 +65,14 @@ mod tests {
4365 }
4466
4567 #[ test]
46- fn test_string_err ( ) {
68+ fn test_uwrite_string_err ( ) {
4769 let p = Pair { x : 0 , y : 1234 } ;
4870 let mut s = String :: < 4 > :: new ( ) ;
4971 assert ! ( uwrite!( s, "{:?}" , p) . is_err( ) ) ;
5072 }
5173
5274 #[ test]
53- fn test_vec ( ) {
75+ fn test_uwrite_vec ( ) {
5476 let a = 123 ;
5577 let b = Pair { x : 0 , y : 1234 } ;
5678
0 commit comments