@@ -78,6 +78,7 @@ enum Void {}
7878
7979/// Padding characters for numeric items.
8080#[ derive( Copy , Clone , PartialEq , Eq , Debug , Hash ) ]
81+ #[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
8182pub enum Pad {
8283 /// No padding.
8384 None ,
@@ -102,6 +103,7 @@ pub enum Pad {
102103/// parsed with the same formatting items.
103104#[ non_exhaustive]
104105#[ derive( Clone , PartialEq , Eq , Debug , Hash ) ]
106+ #[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
105107pub enum Numeric {
106108 /// Full Gregorian year (FW=4, PW=∞).
107109 /// May accept years before 1 BCE or after 9999 CE, given an initial sign (+/-).
@@ -170,12 +172,20 @@ impl fmt::Debug for InternalNumeric {
170172 }
171173}
172174
175+ #[ cfg( feature = "defmt" ) ]
176+ impl defmt:: Format for InternalNumeric {
177+ fn format ( & self , f : defmt:: Formatter ) {
178+ defmt:: write!( f, "<InternalNumeric>" )
179+ }
180+ }
181+
173182/// Fixed-format item types.
174183///
175184/// They have their own rules of formatting and parsing.
176185/// Otherwise noted, they print in the specified cases but parse case-insensitively.
177186#[ non_exhaustive]
178187#[ derive( Clone , PartialEq , Eq , Debug , Hash ) ]
188+ #[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
179189pub enum Fixed {
180190 /// Abbreviated month names.
181191 ///
@@ -260,11 +270,13 @@ pub enum Fixed {
260270
261271/// An opaque type representing fixed-format item types for internal uses only.
262272#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
273+ #[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
263274pub struct InternalFixed {
264275 val : InternalInternal ,
265276}
266277
267278#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
279+ #[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
268280enum InternalInternal {
269281 /// Same as [`TimezoneOffsetColonZ`](#variant.TimezoneOffsetColonZ), but
270282 /// allows missing minutes (per [ISO 8601][iso8601]).
@@ -285,6 +297,7 @@ enum InternalInternal {
285297
286298/// Type for specifying the format of UTC offsets.
287299#[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
300+ #[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
288301pub struct OffsetFormat {
289302 /// See `OffsetPrecision`.
290303 pub precision : OffsetPrecision ,
@@ -298,6 +311,7 @@ pub struct OffsetFormat {
298311
299312/// The precision of an offset from UTC formatting item.
300313#[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
314+ #[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
301315pub enum OffsetPrecision {
302316 /// Format offset from UTC as only hours. Not recommended, it is not uncommon for timezones to
303317 /// have an offset of 30 minutes, 15 minutes, etc.
@@ -319,6 +333,7 @@ pub enum OffsetPrecision {
319333
320334/// The separator between hours and minutes in an offset.
321335#[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
336+ #[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
322337pub enum Colons {
323338 /// No separator
324339 None ,
@@ -350,6 +365,23 @@ pub enum Item<'a> {
350365 Error ,
351366}
352367
368+ #[ cfg( feature = "defmt" ) ]
369+ impl < ' a > defmt:: Format for Item < ' a > {
370+ fn format ( & self , f : defmt:: Formatter ) {
371+ match self {
372+ Item :: Literal ( v) => defmt:: write!( f, "Literal {{ {} }}" , v) ,
373+ #[ cfg( feature = "alloc" ) ]
374+ Item :: OwnedLiteral ( _) => { }
375+ Item :: Space ( v) => defmt:: write!( f, "Space {{ {} }}" , v) ,
376+ #[ cfg( feature = "alloc" ) ]
377+ Item :: OwnedSpace ( _) => { }
378+ Item :: Numeric ( u, v) => defmt:: write!( f, "Numeric {{ {}, {} }}" , u, v) ,
379+ Item :: Fixed ( v) => defmt:: write!( f, "Fixed {{ {} }}" , v) ,
380+ Item :: Error => defmt:: write!( f, "Error" ) ,
381+ }
382+ }
383+ }
384+
353385const fn num ( numeric : Numeric ) -> Item < ' static > {
354386 Item :: Numeric ( numeric, Pad :: None )
355387}
@@ -388,6 +420,7 @@ impl Item<'_> {
388420
389421/// An error from the `parse` function.
390422#[ derive( Debug , Clone , PartialEq , Eq , Copy , Hash ) ]
423+ #[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
391424pub struct ParseError ( ParseErrorKind ) ;
392425
393426impl ParseError {
@@ -400,6 +433,7 @@ impl ParseError {
400433/// The category of parse error
401434#[ allow( clippy:: manual_non_exhaustive) ]
402435#[ derive( Debug , Clone , PartialEq , Eq , Copy , Hash ) ]
436+ #[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
403437pub enum ParseErrorKind {
404438 /// Given field is out of permitted range.
405439 OutOfRange ,
0 commit comments