@@ -3,8 +3,18 @@ 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
+ fn fmt < W > ( & self , f : & mut ufmt:: Formatter < ' _ , W > ) -> Result < ( ) , W :: Error >
11
+ where
12
+ W : uWrite + ?Sized ,
13
+ {
14
+ f. write_str ( & self . as_str ( ) )
15
+ }
16
+ }
17
+
8
18
impl < S : StringStorage + ?Sized > uWrite for StringInner < S > {
9
19
type Error = CapacityError ;
10
20
fn write_str ( & mut self , s : & str ) -> Result < ( ) , Self :: Error > {
@@ -32,7 +42,16 @@ mod tests {
32
42
}
33
43
34
44
#[ test]
35
- fn test_string ( ) {
45
+ fn test_udisplay_string ( ) {
46
+ let str_a = String :: < 32 > :: try_from ( "world" ) . unwrap ( ) ;
47
+ let mut str_b = String :: < 32 > :: new ( ) ;
48
+ uwrite ! ( str_b, "Hello {}!" , str_a) . unwrap ( ) ;
49
+
50
+ assert_eq ! ( str_b, "Hello world!" ) ;
51
+ }
52
+
53
+ #[ test]
54
+ fn test_uwrite_string ( ) {
36
55
let a = 123 ;
37
56
let b = Pair { x : 0 , y : 1234 } ;
38
57
@@ -43,14 +62,14 @@ mod tests {
43
62
}
44
63
45
64
#[ test]
46
- fn test_string_err ( ) {
65
+ fn test_uwrite_string_err ( ) {
47
66
let p = Pair { x : 0 , y : 1234 } ;
48
67
let mut s = String :: < 4 > :: new ( ) ;
49
68
assert ! ( uwrite!( s, "{:?}" , p) . is_err( ) ) ;
50
69
}
51
70
52
71
#[ test]
53
- fn test_vec ( ) {
72
+ fn test_uwrite_vec ( ) {
54
73
let a = 123 ;
55
74
let b = Pair { x : 0 , y : 1234 } ;
56
75
0 commit comments