1use crate::frame::FrameRef;
2use crate::function::Function;
3use crate::map::{Map, Result, ValueIter};
4use crate::node::Node;
5
6#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
8pub enum ValueType {
9 Int,
10 Float,
11 Data,
12 VideoNode,
13 AudioNode,
14 VideoFrame,
15 AudioFrame,
16 Function,
17}
18
19pub trait Value<'map, 'elem: 'map>: Sized {
21 fn get_from_map(map: &'map Map<'elem>, key: &str) -> Result<Self>;
23
24 fn get_iter_from_map(map: &'map Map<'elem>, key: &str) -> Result<ValueIter<'map, 'elem, Self>>;
26
27 fn store_in_map(map: &'map mut Map<'elem>, key: &str, x: &Self) -> Result<()>;
29
30 fn append_to_map(map: &'map mut Map<'elem>, key: &str, x: &Self) -> Result<()>;
32}
33
34impl<'map, 'elem: 'map> Value<'map, 'elem> for i64 {
35 #[inline]
36 fn get_from_map(map: &Map, key: &str) -> Result<Self> {
37 map.get_int(key)
38 }
39
40 #[inline]
41 fn get_iter_from_map(map: &'map Map<'elem>, key: &str) -> Result<ValueIter<'map, 'elem, Self>> {
42 map.get_int_iter(key)
43 }
44
45 #[inline]
46 fn store_in_map(map: &mut Map, key: &str, x: &Self) -> Result<()> {
47 map.set_int(key, *x)
48 }
49
50 #[inline]
51 fn append_to_map(map: &mut Map, key: &str, x: &Self) -> Result<()> {
52 map.append_int(key, *x)
53 }
54}
55
56impl<'map, 'elem: 'map> Value<'map, 'elem> for f64 {
57 fn get_from_map(map: &Map, key: &str) -> Result<Self> {
58 map.get_float(key)
59 }
60
61 #[inline]
62 fn get_iter_from_map(map: &'map Map<'elem>, key: &str) -> Result<ValueIter<'map, 'elem, Self>> {
63 map.get_float_iter(key)
64 }
65
66 #[inline]
67 fn store_in_map(map: &mut Map, key: &str, x: &Self) -> Result<()> {
68 map.set_float(key, *x)
69 }
70
71 #[inline]
72 fn append_to_map(map: &mut Map, key: &str, x: &Self) -> Result<()> {
73 map.append_float(key, *x)
74 }
75}
76
77impl<'map, 'elem: 'map> Value<'map, 'elem> for &'map [u8] {
78 #[inline]
79 fn get_from_map(map: &'map Map, key: &str) -> Result<Self> {
80 map.get_data(key)
81 }
82
83 #[inline]
84 fn get_iter_from_map(map: &'map Map<'elem>, key: &str) -> Result<ValueIter<'map, 'elem, Self>> {
85 map.get_data_iter(key)
86 }
87
88 #[inline]
89 fn store_in_map(map: &'map mut Map, key: &str, x: &Self) -> Result<()> {
90 map.set_data(key, x)
91 }
92
93 #[inline]
94 fn append_to_map(map: &'map mut Map, key: &str, x: &Self) -> Result<()> {
95 map.append_data(key, x)
96 }
97}
98
99impl<'map, 'elem: 'map> Value<'map, 'elem> for Node<'elem> {
100 #[inline]
101 fn get_from_map(map: &Map<'elem>, key: &str) -> Result<Self> {
102 map.get_video_node(key)
103 }
104
105 #[inline]
106 fn get_iter_from_map(map: &'map Map<'elem>, key: &str) -> Result<ValueIter<'map, 'elem, Self>> {
107 map.get_video_node_iter(key)
108 }
109
110 #[inline]
111 fn store_in_map(map: &mut Map<'elem>, key: &str, x: &Self) -> Result<()> {
112 map.set_node(key, x)
113 }
114
115 #[inline]
116 fn append_to_map(map: &mut Map<'elem>, key: &str, x: &Self) -> Result<()> {
117 map.append_node(key, x)
118 }
119}
120
121impl<'map, 'elem: 'map> Value<'map, 'elem> for FrameRef<'elem> {
122 #[inline]
123 fn get_from_map(map: &Map<'elem>, key: &str) -> Result<Self> {
124 map.get_video_frame(key)
125 }
126
127 #[inline]
128 fn get_iter_from_map(map: &'map Map<'elem>, key: &str) -> Result<ValueIter<'map, 'elem, Self>> {
129 map.get_video_frame_iter(key)
130 }
131
132 #[inline]
133 fn store_in_map(map: &mut Map<'elem>, key: &str, x: &Self) -> Result<()> {
134 map.set_frame(key, x)
135 }
136
137 #[inline]
138 fn append_to_map(map: &mut Map<'elem>, key: &str, x: &Self) -> Result<()> {
139 map.append_frame(key, x)
140 }
141}
142
143impl<'map, 'elem: 'map> Value<'map, 'elem> for Function<'elem> {
144 #[inline]
145 fn get_from_map(map: &Map<'elem>, key: &str) -> Result<Self> {
146 map.get_function(key)
147 }
148
149 #[inline]
150 fn get_iter_from_map(map: &'map Map<'elem>, key: &str) -> Result<ValueIter<'map, 'elem, Self>> {
151 map.get_function_iter(key)
152 }
153
154 #[inline]
155 fn store_in_map(map: &mut Map<'elem>, key: &str, x: &Self) -> Result<()> {
156 map.set_function(key, x)
157 }
158
159 #[inline]
160 fn append_to_map(map: &mut Map<'elem>, key: &str, x: &Self) -> Result<()> {
161 map.append_function(key, x)
162 }
163}