1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use anyhow::anyhow;
use anyhow::Result;
use crate::bindings;
#[derive(Debug)]
pub enum GenericValue {
Integer(i32),
Float(f32),
Pointer(*mut std::os::raw::c_void),
Func(bindings::VAGenericFunc),
}
impl TryFrom<bindings::VAGenericValue> for GenericValue {
type Error = anyhow::Error;
fn try_from(value: bindings::VAGenericValue) -> Result<Self, Self::Error> {
match value.type_ {
bindings::VAGenericValueType::VAGenericValueTypeInteger => {
Ok(Self::Integer(unsafe { value.value.i }))
}
bindings::VAGenericValueType::VAGenericValueTypeFloat => {
Ok(Self::Float(unsafe { value.value.f }))
}
bindings::VAGenericValueType::VAGenericValueTypePointer => {
Ok(Self::Pointer(unsafe { value.value.p }))
}
bindings::VAGenericValueType::VAGenericValueTypeFunc => {
Ok(Self::Func(unsafe { value.value.fn_ }))
}
other => Err(anyhow!(
"Conversion failed for unexpected VAGenericValueType: {}",
other
)),
}
}
}