Skip to content

Commit

Permalink
hand implemented fmt::Debug for ArchivedDateTime
Browse files Browse the repository at this point in the history
  • Loading branch information
mkatychev committed Oct 9, 2023
1 parent 3faca1b commit 57c2fbd
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1506,6 +1506,31 @@ impl<Tz: TimeZone> fmt::Debug for DateTime<Tz> {
}
}

// `fmt::Debug` is hand implemented for the `rkyv::Archive` variant of `DateTime` because
// deriving a trait recursively does not propagate trait defined associated types with their own
// constraints:
// In our case `<<Tz as offset::TimeZone>::Offset as Archive>::Archived`
// cannot be formatted using `{:?}` because it doesn't implement `Debug`.
// See below for further discussion:
// * https://github.com/rust-lang/rust/issues/26925
// * https://github.com/rkyv/rkyv/issues/333
// * https://github.com/dtolnay/syn/issues/370
#[cfg(feature = "rkyv-validation")]
impl<Tz: TimeZone> fmt::Debug for ArchivedDateTime<Tz>
where
Tz: Archive,
<Tz as Archive>::Archived: fmt::Debug,
<<Tz as TimeZone>::Offset as Archive>::Archived: fmt::Debug,
<Tz as TimeZone>::Offset: fmt::Debug + Archive,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("ArchivedDateTime")
.field("datetime", &self.datetime)
.field("offset", &self.offset)
.finish()
}
}

impl<Tz: TimeZone> fmt::Display for DateTime<Tz>
where
Tz::Offset: fmt::Display,
Expand Down

0 comments on commit 57c2fbd

Please sign in to comment.