@@ -15,6 +15,29 @@ use crate::io::{self, Read};
15
15
use crate :: ln:: msgs;
16
16
use crate :: util:: ser:: { Writeable , Writer , Readable } ;
17
17
18
+ /// Struct to `Display` fields in a safe way using `PrintableString`
19
+ #[ derive( Clone , Debug , PartialEq , Eq ) ]
20
+ pub struct SanitizedString ( pub String ) ;
21
+
22
+ impl Writeable for SanitizedString {
23
+ fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
24
+ self . 0 . write ( w)
25
+ }
26
+ }
27
+
28
+ impl Readable for SanitizedString {
29
+ fn read < R : Read > ( r : & mut R ) -> Result < Self , msgs:: DecodeError > {
30
+ let s: String = Readable :: read ( r) ?;
31
+ Ok ( Self ( s) )
32
+ }
33
+ }
34
+
35
+ impl fmt:: Display for SanitizedString {
36
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
37
+ PrintableString ( & self . 0 ) . fmt ( f)
38
+ }
39
+ }
40
+
18
41
/// A string that displays only printable characters, replacing control characters with
19
42
/// [`core::char::REPLACEMENT_CHARACTER`].
20
43
#[ derive( Debug , PartialEq ) ]
@@ -44,26 +67,3 @@ mod tests {
44
67
) ;
45
68
}
46
69
}
47
-
48
- /// Struct to `Display` fields in a safe way using `PrintableString`
49
- #[ derive( Clone , Debug , PartialEq , Eq ) ]
50
- pub struct SanitizedString ( pub String ) ;
51
-
52
- impl Writeable for SanitizedString {
53
- fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
54
- self . 0 . write ( w)
55
- }
56
- }
57
-
58
- impl Readable for SanitizedString {
59
- fn read < R : Read > ( r : & mut R ) -> Result < Self , msgs:: DecodeError > {
60
- let s: String = Readable :: read ( r) ?;
61
- Ok ( Self ( s) )
62
- }
63
- }
64
-
65
- impl fmt:: Display for SanitizedString {
66
- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
67
- PrintableString ( & self . 0 ) . fmt ( f)
68
- }
69
- }
0 commit comments