Skip to content

Commit 59d558f

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

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Implement `defmt::Format` for `EscapedStr`, `EscapedStringFragment` and `StringUnescapeError`.
13+
1014
## [v0.6.0] - 2024-08-07
1115

1216
### Breaking

src/str.rs

Lines changed: 7 additions & 4 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
}
@@ -88,7 +90,7 @@ fn unescape_next_fragment(
8890
/// #[serde(borrow)]
8991
/// description: serde_json_core::str::EscapedStr<'a>,
9092
/// }
91-
///
93+
///
9294
/// serde_json_core::de::from_str_escaped::<Event<'_>>(
9395
/// r#"{ "name": "Party\u0021", "description": "I'm throwing a party! Hopefully the \u2600 shines!" }"#,
9496
/// &mut [0; 8],
@@ -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)