diff --git a/CHANGELOG.md b/CHANGELOG.md index 208cc839..6fa57126 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Added + +- Implement `defmt::Format` for `EscapedStr`, `EscapedStringFragment` and `StringUnescapeError`. +- Implement `Default` for `EscapedStr` (returning an empty string). + ## [v0.6.0] - 2024-08-07 ### Breaking diff --git a/src/str.rs b/src/str.rs index ab122485..2a1b8e2f 100644 --- a/src/str.rs +++ b/src/str.rs @@ -2,8 +2,9 @@ use core::fmt; -#[derive(Debug)] /// A fragment of an escaped string +#[derive(Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum EscapedStringFragment<'a> { /// A series of characters which weren't escaped in the input. NotEscaped(&'a str), @@ -11,8 +12,9 @@ pub enum EscapedStringFragment<'a> { Escaped(char), } -#[derive(Debug)] /// Errors occuring while unescaping strings. +#[derive(Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum StringUnescapeError { /// Failed to unescape a character due to an invalid escape sequence. InvalidEscapeSequence, @@ -23,7 +25,7 @@ impl fmt::Display for StringUnescapeError { match self { StringUnescapeError::InvalidEscapeSequence => write!( f, - "Failed to unescape a character due to an invalid escape sequence." + "Failed to unescape a character due to an invalid escape sequence" ), } } @@ -88,15 +90,16 @@ fn unescape_next_fragment( /// #[serde(borrow)] /// description: serde_json_core::str::EscapedStr<'a>, /// } -/// +/// /// serde_json_core::de::from_str_escaped::>( /// r#"{ "name": "Party\u0021", "description": "I'm throwing a party! Hopefully the \u2600 shines!" }"#, /// &mut [0; 8], /// ) /// .unwrap(); /// ``` -#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] #[serde(rename = "__serde_json_core_escaped_string__")] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct EscapedStr<'a>(pub &'a str); impl<'a> EscapedStr<'a> {