more implementations

This commit is contained in:
Erica Z 2024-11-03 10:20:31 +01:00
parent d3a37dec1b
commit c2d9eb61e2

View file

@ -7,9 +7,9 @@ pub trait SetProperty {
unsafe fn set_property(self, ctx: *mut ffi::mpv_handle, name: *const c_char) -> c_int; unsafe fn set_property(self, ctx: *mut ffi::mpv_handle, name: *const c_char) -> c_int;
} }
impl<'a> SetProperty for &'a str { impl SetProperty for String {
unsafe fn set_property(self, ctx: *mut ffi::mpv_handle, name: *const c_char) -> c_int { unsafe fn set_property(self, ctx: *mut ffi::mpv_handle, name: *const c_char) -> c_int {
// need to add zero terminator // should add zero terminator directly
let value = CString::new(self).expect("null bytes in string property value"); let value = CString::new(self).expect("null bytes in string property value");
let value_ptr: *const c_char = value.as_ptr(); let value_ptr: *const c_char = value.as_ptr();
ffi::mpv_set_property( ffi::mpv_set_property(
@ -21,6 +21,13 @@ impl<'a> SetProperty for &'a str {
} }
} }
impl<'a> SetProperty for &'a str {
unsafe fn set_property(self, ctx: *mut ffi::mpv_handle, name: *const c_char) -> c_int {
// need to add zero terminator
String::set_property(self.into(), ctx, name)
}
}
impl SetProperty for bool { impl SetProperty for bool {
unsafe fn set_property(self, ctx: *mut ffi::mpv_handle, name: *const c_char) -> c_int { unsafe fn set_property(self, ctx: *mut ffi::mpv_handle, name: *const c_char) -> c_int {
let value: c_int = if self { 1 } else { 0 }; let value: c_int = if self { 1 } else { 0 };
@ -32,3 +39,25 @@ impl SetProperty for bool {
) )
} }
} }
impl SetProperty for i64 {
unsafe fn set_property(self, ctx: *mut ffi::mpv_handle, name: *const c_char) -> c_int {
ffi::mpv_set_property(
ctx,
name,
ffi::mpv_format_MPV_FORMAT_INT64,
std::ptr::from_ref::<i64>(&self) as *mut c_void,
)
}
}
impl SetProperty for f64 {
unsafe fn set_property(self, ctx: *mut ffi::mpv_handle, name: *const c_char) -> c_int {
ffi::mpv_set_property(
ctx,
name,
ffi::mpv_format_MPV_FORMAT_DOUBLE,
std::ptr::from_ref::<f64>(&self) as *mut c_void,
)
}
}