vapoursynth4_rs/
function.rs1use crate::{api::Api, ffi, map::Map};
2
3#[derive(Debug, PartialEq, Eq, Hash)]
4pub struct Function {
5 handle: *const ffi::VSFunction,
6 api: Api,
7}
8
9unsafe impl Send for Function {}
10
11impl Function {
12 pub(crate) unsafe fn from_ptr(ptr: *mut ffi::VSFunction, api: Api) -> Self {
13 Self { handle: ptr, api }
14 }
15
16 #[must_use]
17 pub fn as_ptr(&self) -> *mut ffi::VSFunction {
18 self.handle.cast_mut()
19 }
20
21 pub fn call(&mut self, in_: &Map, out: &mut Map) {
22 unsafe {
23 (self.api.callFunction)(self.as_ptr(), in_.as_ptr(), out.as_ptr());
24 }
25 }
26}
27
28impl Drop for Function {
29 fn drop(&mut self) {
30 unsafe { (self.api.freeFunction)(self.as_ptr()) }
31 }
32}
33
34impl Clone for Function {
35 fn clone(&self) -> Self {
36 unsafe { Self::from_ptr((self.api.addFunctionRef)(self.as_ptr()), self.api) }
37 }
38}