impl debug for mpv handle

This commit is contained in:
Erica Z 2024-11-03 09:54:22 +01:00
parent f8d139e36f
commit 070f25f862

View file

@ -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");