gstreamer: query: manually implement Debug

Allow us to display more useful information.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1268>
This commit is contained in:
Guillaume Desmottes 2023-05-22 14:20:29 +02:00
parent 71b77c513d
commit 53173eb46c

View file

@ -200,7 +200,6 @@ pub enum QueryViewMut<'a> {
macro_rules! declare_concrete_query( macro_rules! declare_concrete_query(
($name:ident, $param:ident) => { ($name:ident, $param:ident) => {
#[derive(Debug)]
#[repr(transparent)] #[repr(transparent)]
pub struct $name<$param = QueryRef>($param); pub struct $name<$param = QueryRef>($param);
@ -351,6 +350,16 @@ impl Position {
} }
} }
impl std::fmt::Debug for Position {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Position")
.field("structure", &self.query().structure())
.field("result", &self.result())
.field("format", &self.format())
.finish()
}
}
declare_concrete_query!(Duration, T); declare_concrete_query!(Duration, T);
impl Duration<Query> { impl Duration<Query> {
#[doc(alias = "gst_query_new_duration")] #[doc(alias = "gst_query_new_duration")]
@ -399,6 +408,16 @@ impl Duration {
} }
} }
impl std::fmt::Debug for Duration {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Duration")
.field("structure", &self.query().structure())
.field("result", &self.result())
.field("format", &self.format())
.finish()
}
}
declare_concrete_query!(Latency, T); declare_concrete_query!(Latency, T);
impl Latency<Query> { impl Latency<Query> {
#[doc(alias = "gst_query_new_latency")] #[doc(alias = "gst_query_new_latency")]
@ -456,6 +475,15 @@ impl Latency {
} }
} }
impl std::fmt::Debug for Latency {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Latency")
.field("structure", &self.query().structure())
.field("result", &self.result())
.finish()
}
}
declare_concrete_query!(Seeking, T); declare_concrete_query!(Seeking, T);
impl Seeking<Query> { impl Seeking<Query> {
#[doc(alias = "gst_query_new_seeking")] #[doc(alias = "gst_query_new_seeking")]
@ -529,6 +557,16 @@ impl Seeking {
} }
} }
impl std::fmt::Debug for Seeking {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Seeking")
.field("structure", &self.query().structure())
.field("result", &self.result())
.field("format", &self.format())
.finish()
}
}
declare_concrete_query!(Segment, T); declare_concrete_query!(Segment, T);
impl Segment<Query> { impl Segment<Query> {
#[doc(alias = "gst_query_new_segment")] #[doc(alias = "gst_query_new_segment")]
@ -601,6 +639,16 @@ impl Segment {
} }
} }
impl std::fmt::Debug for Segment {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Segment")
.field("structure", &self.query().structure())
.field("result", &self.result())
.field("format", &self.format())
.finish()
}
}
declare_concrete_query!(Convert, T); declare_concrete_query!(Convert, T);
impl Convert<Query> { impl Convert<Query> {
#[doc(alias = "gst_query_new_convert")] #[doc(alias = "gst_query_new_convert")]
@ -675,6 +723,18 @@ impl Convert {
} }
} }
impl std::fmt::Debug for Convert {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let (source, dest) = self.result();
f.debug_struct("Convert")
.field("structure", &self.query().structure())
.field("source", &source)
.field("dest", &dest)
.finish()
}
}
declare_concrete_query!(Formats, T); declare_concrete_query!(Formats, T);
impl Formats<Query> { impl Formats<Query> {
#[doc(alias = "gst_query_new_formats")] #[doc(alias = "gst_query_new_formats")]
@ -721,6 +781,15 @@ impl Formats {
} }
} }
impl std::fmt::Debug for Formats {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Formats")
.field("structure", &self.query().structure())
.field("result", &self.result())
.finish()
}
}
declare_concrete_query!(Buffering, T); declare_concrete_query!(Buffering, T);
impl Buffering<Query> { impl Buffering<Query> {
#[doc(alias = "gst_query_new_buffering")] #[doc(alias = "gst_query_new_buffering")]
@ -927,6 +996,17 @@ impl Buffering {
} }
} }
impl std::fmt::Debug for Buffering {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Buffering")
.field("structure", &self.query().structure())
.field("format", &self.format())
.field("percent", &self.percent())
.field("range", &self.range())
.finish()
}
}
declare_concrete_query!(Custom, T); declare_concrete_query!(Custom, T);
impl Custom<Query> { impl Custom<Query> {
#[doc(alias = "gst_query_new_custom")] #[doc(alias = "gst_query_new_custom")]
@ -941,6 +1021,14 @@ impl Custom<Query> {
} }
} }
impl std::fmt::Debug for Custom {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Custom")
.field("structure", &self.query().structure())
.finish()
}
}
declare_concrete_query!(Uri, T); declare_concrete_query!(Uri, T);
impl Uri<Query> { impl Uri<Query> {
#[doc(alias = "gst_query_new_uri")] #[doc(alias = "gst_query_new_uri")]
@ -1016,6 +1104,18 @@ impl Uri {
} }
} }
impl std::fmt::Debug for Uri {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let (redirection, permanent) = self.redirection();
f.debug_struct("Uri")
.field("structure", &self.query().structure())
.field("uri", &self.uri())
.field("redirection", &redirection)
.field("redirection-permanent", &permanent)
.finish()
}
}
declare_concrete_query!(Allocation, T); declare_concrete_query!(Allocation, T);
impl Allocation<Query> { impl Allocation<Query> {
#[doc(alias = "gst_query_new_allocation")] #[doc(alias = "gst_query_new_allocation")]
@ -1279,6 +1379,20 @@ impl Allocation {
} }
} }
impl std::fmt::Debug for Allocation {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let (caps, need_pool) = self.get();
f.debug_struct("Allocation")
.field("structure", &self.query().structure())
.field("caps", &caps)
.field("need-pool", &need_pool)
.field("allocation-params", &self.allocation_params())
.field("allocation-pools", &self.allocation_pools())
.field("allocation-metas", &self.allocation_metas())
.finish()
}
}
declare_concrete_query!(Scheduling, T); declare_concrete_query!(Scheduling, T);
impl Scheduling<Query> { impl Scheduling<Query> {
#[doc(alias = "gst_query_new_scheduling")] #[doc(alias = "gst_query_new_scheduling")]
@ -1387,6 +1501,16 @@ impl Scheduling {
} }
} }
impl std::fmt::Debug for Scheduling {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Scheduling")
.field("structure", &self.query().structure())
.field("result", &self.result())
.field("scheduling-modes", &self.scheduling_modes())
.finish()
}
}
declare_concrete_query!(AcceptCaps, T); declare_concrete_query!(AcceptCaps, T);
impl AcceptCaps<Query> { impl AcceptCaps<Query> {
#[doc(alias = "gst_query_new_accept_caps")] #[doc(alias = "gst_query_new_accept_caps")]
@ -1435,6 +1559,16 @@ impl AcceptCaps {
} }
} }
impl std::fmt::Debug for AcceptCaps {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("AcceptCaps")
.field("structure", &self.query().structure())
.field("result", &self.result())
.field("caps", &self.caps())
.finish()
}
}
declare_concrete_query!(Caps, T); declare_concrete_query!(Caps, T);
impl Caps<Query> { impl Caps<Query> {
#[doc(alias = "gst_query_new_caps")] #[doc(alias = "gst_query_new_caps")]
@ -1502,6 +1636,16 @@ impl Caps {
} }
} }
impl std::fmt::Debug for Caps {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Caps")
.field("structure", &self.query().structure())
.field("result", &self.result())
.field("filter", &self.filter())
.finish()
}
}
declare_concrete_query!(Drain, T); declare_concrete_query!(Drain, T);
impl Drain<Query> { impl Drain<Query> {
#[doc(alias = "gst_query_new_drain")] #[doc(alias = "gst_query_new_drain")]
@ -1517,6 +1661,14 @@ impl Default for Drain<Query> {
} }
} }
impl std::fmt::Debug for Drain {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Drain")
.field("structure", &self.query().structure())
.finish()
}
}
declare_concrete_query!(Context, T); declare_concrete_query!(Context, T);
impl Context<Query> { impl Context<Query> {
#[doc(alias = "gst_query_new_context")] #[doc(alias = "gst_query_new_context")]
@ -1578,6 +1730,16 @@ impl Context {
} }
} }
impl std::fmt::Debug for Context {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Context")
.field("structure", &self.query().structure())
.field("context", &self.context())
.field("context-type", &self.context_type())
.finish()
}
}
#[cfg(feature = "v1_16")] #[cfg(feature = "v1_16")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))] #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
declare_concrete_query!(Bitrate, T); declare_concrete_query!(Bitrate, T);
@ -1621,6 +1783,16 @@ impl Bitrate {
} }
} }
#[cfg(feature = "v1_16")]
impl std::fmt::Debug for Bitrate {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Bitrate")
.field("structure", &self.query().structure())
.field("bitrate", &self.bitrate())
.finish()
}
}
#[cfg(feature = "v1_22")] #[cfg(feature = "v1_22")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))] #[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
declare_concrete_query!(Selectable, T); declare_concrete_query!(Selectable, T);
@ -1664,8 +1836,26 @@ impl Selectable {
} }
} }
#[cfg(feature = "v1_22")]
impl std::fmt::Debug for Selectable {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Selectable")
.field("structure", &self.query().structure())
.field("selectable", &self.selectable())
.finish()
}
}
declare_concrete_query!(Other, T); declare_concrete_query!(Other, T);
impl std::fmt::Debug for Other {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Other")
.field("structure", &self.query().structure())
.finish()
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;