Skip to content

Commit

Permalink
ndk/media_format: Implement Debug in terms of Display (#450)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
MarijnS95 committed Nov 22, 2023
1 parent 1c8570b commit 2d269e1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ndk/src/media/media_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use crate::media_error::{MediaError, Result};
/// A native [`AMediaFormat *`]
///
/// [`AMediaFormat *`]: https://developer.android.com/ndk/reference/group/media#amediaformat
#[derive(Debug)]
#[doc(alias = "AMediaFormat")]
pub struct MediaFormat {
inner: NonNull<ffi::AMediaFormat>,
Expand All @@ -29,6 +28,13 @@ impl fmt::Display for MediaFormat {
}
}

impl fmt::Debug for MediaFormat {
#[doc(alias = "AMediaFormat_toString")]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "MediaFormat({:?}: {})", self.inner, self)
}
}

impl Default for MediaFormat {
#[doc(alias = "AMediaFormat_new")]
fn default() -> Self {
Expand Down

0 comments on commit 2d269e1

Please sign in to comment.