@@ -3,17 +3,30 @@ use crate::{
3
3
vec:: { VecInner , VecStorage } ,
4
4
CapacityError ,
5
5
} ;
6
+ use ufmt:: uDisplay;
6
7
use ufmt_write:: uWrite;
7
8
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
+
8
19
impl < S : StringStorage + ?Sized > uWrite for StringInner < S > {
9
20
type Error = CapacityError ;
21
+ #[ inline]
10
22
fn write_str ( & mut self , s : & str ) -> Result < ( ) , Self :: Error > {
11
23
self . push_str ( s)
12
24
}
13
25
}
14
26
15
27
impl < S : VecStorage < u8 > + ?Sized > uWrite for VecInner < u8 , S > {
16
28
type Error = CapacityError ;
29
+ #[ inline]
17
30
fn write_str ( & mut self , s : & str ) -> Result < ( ) , Self :: Error > {
18
31
self . extend_from_slice ( s. as_bytes ( ) )
19
32
}
@@ -32,7 +45,16 @@ mod tests {
32
45
}
33
46
34
47
#[ 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 ( ) {
36
58
let a = 123 ;
37
59
let b = Pair { x : 0 , y : 1234 } ;
38
60
@@ -43,14 +65,14 @@ mod tests {
43
65
}
44
66
45
67
#[ test]
46
- fn test_string_err ( ) {
68
+ fn test_uwrite_string_err ( ) {
47
69
let p = Pair { x : 0 , y : 1234 } ;
48
70
let mut s = String :: < 4 > :: new ( ) ;
49
71
assert ! ( uwrite!( s, "{:?}" , p) . is_err( ) ) ;
50
72
}
51
73
52
74
#[ test]
53
- fn test_vec ( ) {
75
+ fn test_uwrite_vec ( ) {
54
76
let a = 123 ;
55
77
let b = Pair { x : 0 , y : 1234 } ;
56
78
0 commit comments