From 2d269e1a8dc26fefecfe0d26d77287526a80e88a Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Wed, 22 Nov 2023 22:06:47 +0100 Subject: [PATCH] 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). --- ndk/src/media/media_format.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ndk/src/media/media_format.rs b/ndk/src/media/media_format.rs index 028275d6..6752ff8f 100644 --- a/ndk/src/media/media_format.rs +++ b/ndk/src/media/media_format.rs @@ -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, @@ -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 {