more implementations
This commit is contained in:
parent
d3a37dec1b
commit
c2d9eb61e2
1 changed files with 31 additions and 2 deletions
|
@ -7,9 +7,9 @@ pub trait SetProperty {
|
|||
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 {
|
||||
// need to add zero terminator
|
||||
// should add zero terminator directly
|
||||
let value = CString::new(self).expect("null bytes in string property value");
|
||||
let value_ptr: *const c_char = value.as_ptr();
|
||||
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 {
|
||||
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 };
|
||||
|
@ -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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue