Skip to content

Commit 2d269e1

Browse files
authored
ndk/media_format: Implement Debug in terms of Display (#450)
Currently `Debug` only prints a raw pointer which is rather useless to look at. In addition to the pointer, also print the `Display` representation of `MediaFormat` which uses Android's `toString()` function to create a human-readable string of the various fields set inside of it. On a side-note it is "great" to see that `toString()` is not currently available as a user function via a lifetimed `CStr` as it is invalidated in a nontrivial way (e.g. when `toString()` is called again, and possibly also when `set_()` functions are called which are not currently borrowing it mutably).
1 parent 1c8570b commit 2d269e1

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

ndk/src/media/media_format.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use crate::media_error::{MediaError, Result};
1414
/// A native [`AMediaFormat *`]
1515
///
1616
/// [`AMediaFormat *`]: https://developer.android.com/ndk/reference/group/media#amediaformat
17-
#[derive(Debug)]
1817
#[doc(alias = "AMediaFormat")]
1918
pub struct MediaFormat {
2019
inner: NonNull<ffi::AMediaFormat>,
@@ -29,6 +28,13 @@ impl fmt::Display for MediaFormat {
2928
}
3029
}
3130

31+
impl fmt::Debug for MediaFormat {
32+
#[doc(alias = "AMediaFormat_toString")]
33+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34+
write!(f, "MediaFormat({:?}: {})", self.inner, self)
35+
}
36+
}
37+
3238
impl Default for MediaFormat {
3339
#[doc(alias = "AMediaFormat_new")]
3440
fn default() -> Self {

0 commit comments

Comments
 (0)