gstreamer/clock_time: Format Debug like Display

This allows us to drop `.to_string()` from the custom Debug
implementations, which now also no longer print as strings.
This commit is contained in:
Jan Alexander Steffens (heftig) 2021-09-22 23:07:28 +02:00
parent 14edcf9aaf
commit c05d2e24af
No known key found for this signature in database
GPG key ID: 3B94A80E50A477C7
5 changed files with 27 additions and 16 deletions

View file

@ -941,9 +941,9 @@ impl fmt::Debug for BufferRef {
f.debug_struct("Buffer") f.debug_struct("Buffer")
.field("ptr", unsafe { &self.as_ptr() }) .field("ptr", unsafe { &self.as_ptr() })
.field("pts", &self.pts().display().to_string()) .field("pts", &self.pts().display())
.field("dts", &self.dts().display().to_string()) .field("dts", &self.dts().display())
.field("duration", &self.duration().display().to_string()) .field("duration", &self.duration().display())
.field("size", &self.size()) .field("size", &self.size())
.field("offset", &self.offset()) .field("offset", &self.offset())
.field("offset_end", &self.offset_end()) .field("offset_end", &self.offset_end())

View file

@ -197,8 +197,8 @@ impl fmt::Debug for BufferListRef {
f.debug_struct("BufferList") f.debug_struct("BufferList")
.field("ptr", unsafe { &self.as_ptr() }) .field("ptr", unsafe { &self.as_ptr() })
.field("buffers", &self.len()) .field("buffers", &self.len())
.field("pts", &pts.display().to_string()) .field("pts", &pts.display())
.field("dts", &dts.display().to_string()) .field("dts", &dts.display())
.field("size", &size) .field("size", &size)
.finish() .finish()
} }

View file

@ -7,7 +7,7 @@ use std::io::{self, prelude::*};
use std::time::Duration; use std::time::Duration;
use std::{cmp, convert, fmt, str}; use std::{cmp, convert, fmt, str};
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Debug, Default)] #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Default)]
pub struct ClockTime(pub(crate) u64); pub struct ClockTime(pub(crate) u64);
impl ClockTime { impl ClockTime {
@ -419,7 +419,12 @@ impl fmt::Display for ClockTime {
} }
} }
#[derive(Debug)] impl fmt::Debug for ClockTime {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}
pub struct DisplayableOptClockTime(Option<ClockTime>); pub struct DisplayableOptClockTime(Option<ClockTime>);
impl fmt::Display for DisplayableOptClockTime { impl fmt::Display for DisplayableOptClockTime {
@ -428,6 +433,12 @@ impl fmt::Display for DisplayableOptClockTime {
} }
} }
impl fmt::Debug for DisplayableOptClockTime {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}
impl crate::utils::Displayable for Option<ClockTime> { impl crate::utils::Displayable for Option<ClockTime> {
type DisplayImpl = DisplayableOptClockTime; type DisplayImpl = DisplayableOptClockTime;

View file

@ -503,8 +503,8 @@ impl fmt::Debug for ReferenceTimestampMeta {
f.debug_struct("ReferenceTimestampMeta") f.debug_struct("ReferenceTimestampMeta")
.field("reference", &self.reference()) .field("reference", &self.reference())
.field("timestamp", &self.timestamp().display().to_string()) .field("timestamp", &self.timestamp().display())
.field("duration", &self.duration().display().to_string()) .field("duration", &self.duration().display())
.finish() .finish()
} }
} }

View file

@ -591,16 +591,16 @@ impl<T: FormattedValueIntrinsic> fmt::Debug for FormattedSegment<T> {
let segment = segment.downcast_ref::<crate::ClockTime>().unwrap(); let segment = segment.downcast_ref::<crate::ClockTime>().unwrap();
f.debug_struct("Segment") f.debug_struct("Segment")
.field("format", &Format::Time) .field("format", &Format::Time)
.field("start", &segment.start().display().to_string()) .field("start", &segment.start().display())
.field("offset", &segment.offset().display().to_string()) .field("offset", &segment.offset().display())
.field("stop", &segment.stop().display().to_string()) .field("stop", &segment.stop().display())
.field("rate", &segment.rate()) .field("rate", &segment.rate())
.field("applied_rate", &segment.applied_rate()) .field("applied_rate", &segment.applied_rate())
.field("flags", &segment.flags()) .field("flags", &segment.flags())
.field("time", &segment.time().display().to_string()) .field("time", &segment.time().display())
.field("base", &segment.base().display().to_string()) .field("base", &segment.base().display())
.field("position", &segment.position().display().to_string()) .field("position", &segment.position().display())
.field("duration", &segment.duration().display().to_string()) .field("duration", &segment.duration().display())
.finish() .finish()
} }
_ => f _ => f