vapoursynth4_rs/plugin/
types.rs1use std::{borrow::Cow, collections::HashMap};
2
3use crate::map::{Key, KeyStr};
4
5pub enum Type {
6 Int,
7 Float,
8 Data,
9 ANode,
10 VNode,
11 AFrame,
12 VFrame,
13 Func,
14 Array(Box<Type>),
15}
16
17impl Type {
18 #[must_use]
19 pub fn to_args(&self) -> Cow<'static, str> {
20 use Type as t;
21 match self {
22 t::Int => "int".into(),
23 t::Float => "float".into(),
24 t::Data => "data".into(),
25 t::ANode => "anode".into(),
26 t::VNode => "vnode".into(),
27 t::AFrame => "aframe".into(),
28 t::VFrame => "vframe".into(),
29 t::Func => "func".into(),
30 t::Array(t) => t.to_args() + "[]",
31 }
32 }
33}
34
35pub struct TypeBuilder {
36 types: HashMap<Key, (Type, bool)>,
37}
38
39impl TypeBuilder {
40 #[must_use]
41 pub fn new() -> Self {
42 Self {
43 types: HashMap::new(),
44 }
45 }
46
47 pub fn add(&mut self, key: &KeyStr, ty: Type, opt: bool) -> &mut Self {
48 self.types.insert(key.into(), (ty, opt));
49 self
50 }
51
52 #[must_use]
53 pub fn build(self) -> HashMap<Key, (Type, bool)> {
54 self.types
55 }
56}
57
58impl Default for TypeBuilder {
59 fn default() -> Self {
60 Self::new()
61 }
62}