buffer: display metas in Debug

Fix #201
This commit is contained in:
Guillaume Desmottes 2019-05-16 11:43:53 +02:00
parent 0c0c056770
commit 94d4c5b42d

View file

@ -471,6 +471,18 @@ define_iter!(
impl fmt::Debug for BufferRef { impl fmt::Debug for BufferRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use std::cell::RefCell;
struct DebugIter<I>(RefCell<I>);
impl<I: Iterator> fmt::Debug for DebugIter<I>
where
I::Item: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_list().entries(&mut *self.0.borrow_mut()).finish()
}
}
f.debug_struct("Buffer") f.debug_struct("Buffer")
.field("ptr", unsafe { &self.as_ptr() }) .field("ptr", unsafe { &self.as_ptr() })
.field("pts", &self.get_pts().to_string()) .field("pts", &self.get_pts().to_string())
@ -480,6 +492,12 @@ impl fmt::Debug for BufferRef {
.field("offset", &self.get_offset()) .field("offset", &self.get_offset())
.field("offset_end", &self.get_offset_end()) .field("offset_end", &self.get_offset_end())
.field("flags", &self.get_flags()) .field("flags", &self.get_flags())
.field(
"metas",
&DebugIter(RefCell::new(
self.iter_meta::<::Meta>().map(|m| m.get_api()),
)),
)
.finish() .finish()
} }
} }