Skip to content

Commit 86fd733

Browse files
committed
reorder string utils
1 parent 7cb5f8d commit 86fd733

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

lightning/src/util/string.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,29 @@ use crate::io::{self, Read};
1515
use crate::ln::msgs;
1616
use crate::util::ser::{Writeable, Writer, Readable};
1717

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+
1841
/// A string that displays only printable characters, replacing control characters with
1942
/// [`core::char::REPLACEMENT_CHARACTER`].
2043
#[derive(Debug, PartialEq)]
@@ -44,26 +67,3 @@ mod tests {
4467
);
4568
}
4669
}
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

Comments
 (0)