proper display/from_str for timestamp/duration

This commit is contained in:
Christien Rioux 2024-08-02 17:27:03 -05:00
parent 63b5845a8b
commit 627bbf209e
2 changed files with 3 additions and 20 deletions

View File

@ -2,12 +2,7 @@
use super::*; use super::*;
aligned_u64_type!(Timestamp); aligned_u64_type!(Timestamp);
aligned_u64_type_default_display_impl!(Timestamp);
impl fmt::Display for Timestamp {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", debug_ts(self.as_u64()))
}
}
impl fmt::Debug for Timestamp { impl fmt::Debug for Timestamp {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

View File

@ -2,24 +2,12 @@
use super::*; use super::*;
aligned_u64_type!(TimestampDuration); aligned_u64_type!(TimestampDuration);
aligned_u64_type_default_display_impl!(TimestampDuration);
aligned_u64_type_default_math_impl!(TimestampDuration); aligned_u64_type_default_math_impl!(TimestampDuration);
impl fmt::Display for TimestampDuration {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
(&self.0 as &dyn fmt::Display).fmt(f)
}
}
impl FromStr for TimestampDuration {
type Err = <u64 as FromStr>::Err;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(TimestampDuration(u64::from_str(s)?))
}
}
impl fmt::Debug for TimestampDuration { impl fmt::Debug for TimestampDuration {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
(&self.0 as &dyn fmt::Debug).fmt(f) write!(f, "{}", debug_duration(self.as_u64()))
} }
} }