From 070f25f862958da61ea15018bf5468c701840bdf Mon Sep 17 00:00:00 2001 From: Erica Z Date: Sun, 3 Nov 2024 09:54:22 +0100 Subject: [PATCH] impl debug for mpv handle --- src/mpv.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/mpv.rs b/src/mpv.rs index 24a5adc..2d95500 100644 --- a/src/mpv.rs +++ b/src/mpv.rs @@ -66,6 +66,12 @@ impl Default for Handle { } } +impl fmt::Debug for Handle { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { + f.debug_tuple("Handle").field(&self.client_name()).finish() + } +} + impl Handle { pub fn new() -> Self { let inner = @@ -104,6 +110,16 @@ impl Handle { } } + pub fn client_name(&self) -> &str { + unsafe { CStr::from_ptr(ffi::mpv_client_name(self.inner.as_ptr())) } + .to_str() + .unwrap() + } + + pub fn client_id(&self) -> i64 { + unsafe { ffi::mpv_client_id(self.inner.as_ptr()) } + } + pub fn set_property(&self, name: &str, value: impl FormatValue) -> Result<(), Error> { // need to add zero terminator let name = CString::new(name).expect("null bytes in property name");