vapoursynth4_rs/
function.rs

1use 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
9impl Function {
10    pub(crate) unsafe fn from_ptr(ptr: *mut ffi::VSFunction, api: Api) -> Self {
11        Self { handle: ptr, api }
12    }
13
14    #[must_use]
15    pub fn as_ptr(&self) -> *mut ffi::VSFunction {
16        self.handle.cast_mut()
17    }
18
19    pub fn call(&mut self, in_: &Map, out: &mut Map) {
20        unsafe {
21            (self.api.callFunction)(self.as_ptr(), in_.as_ptr(), out.as_ptr());
22        }
23    }
24}
25
26impl Drop for Function {
27    fn drop(&mut self) {
28        unsafe { (self.api.freeFunction)(self.as_ptr()) }
29    }
30}
31
32impl Clone for Function {
33    fn clone(&self) -> Self {
34        unsafe { Self::from_ptr((self.api.addFunctionRef)(self.as_ptr()), self.api) }
35    }
36}