diff --git a/src/mpv/format.rs b/src/mpv/format.rs index d56dd27..5fef129 100644 --- a/src/mpv/format.rs +++ b/src/mpv/format.rs @@ -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::(&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::(&self) as *mut c_void, + ) + } +}