Skip to content

Commit f24f622

Browse files
committed
Implement defmt::Format for EscapedStr and related types.
1 parent 3b369a0 commit f24f622

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/str.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22
33
use core::fmt;
44

5-
#[derive(Debug)]
65
/// A fragment of an escaped string
6+
#[derive(Debug)]
7+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
78
pub enum EscapedStringFragment<'a> {
89
/// A series of characters which weren't escaped in the input.
910
NotEscaped(&'a str),
1011
/// A character which was escaped in the input.
1112
Escaped(char),
1213
}
1314

14-
#[derive(Debug)]
1515
/// Errors occuring while unescaping strings.
16+
#[derive(Debug)]
17+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
1618
pub enum StringUnescapeError {
1719
/// Failed to unescape a character due to an invalid escape sequence.
1820
InvalidEscapeSequence,
@@ -23,7 +25,7 @@ impl fmt::Display for StringUnescapeError {
2325
match self {
2426
StringUnescapeError::InvalidEscapeSequence => write!(
2527
f,
26-
"Failed to unescape a character due to an invalid escape sequence."
28+
"Failed to unescape a character due to an invalid escape sequence"
2729
),
2830
}
2931
}
@@ -97,6 +99,7 @@ fn unescape_next_fragment(
9799
/// ```
98100
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
99101
#[serde(rename = "__serde_json_core_escaped_string__")]
102+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
100103
pub struct EscapedStr<'a>(pub &'a str);
101104

102105
impl<'a> EscapedStr<'a> {

0 commit comments

Comments
 (0)