1use std::collections::VecDeque;
4use std::ops::{Deref, DerefMut};
5
6use crate::value::Value;
7
8#[derive(Default, Debug, Clone)]
14pub struct MultiValue(VecDeque<Value>);
15
16impl MultiValue {
17 pub const fn new() -> MultiValue {
19 MultiValue(VecDeque::new())
20 }
21
22 pub fn with_capacity(capacity: usize) -> MultiValue {
24 MultiValue(VecDeque::with_capacity(capacity))
25 }
26
27 pub fn from_vec(vec: Vec<Value>) -> MultiValue {
29 MultiValue(vec.into())
30 }
31
32 pub fn into_vec(self) -> Vec<Value> {
34 self.0.into()
35 }
36}
37
38impl Deref for MultiValue {
39 type Target = VecDeque<Value>;
40 fn deref(&self) -> &Self::Target {
41 &self.0
42 }
43}
44
45impl DerefMut for MultiValue {
46 fn deref_mut(&mut self) -> &mut Self::Target {
47 &mut self.0
48 }
49}
50
51impl From<Vec<Value>> for MultiValue {
52 fn from(vec: Vec<Value>) -> Self {
53 MultiValue(vec.into())
54 }
55}
56
57impl From<MultiValue> for Vec<Value> {
58 fn from(m: MultiValue) -> Self {
59 m.0.into()
60 }
61}
62
63impl FromIterator<Value> for MultiValue {
64 fn from_iter<I: IntoIterator<Item = Value>>(iter: I) -> Self {
65 MultiValue(VecDeque::from_iter(iter))
66 }
67}
68
69impl IntoIterator for MultiValue {
70 type Item = Value;
71 type IntoIter = std::collections::vec_deque::IntoIter<Value>;
72 fn into_iter(self) -> Self::IntoIter {
73 self.0.into_iter()
74 }
75}
76
77impl<'a> IntoIterator for &'a MultiValue {
78 type Item = &'a Value;
79 type IntoIter = std::collections::vec_deque::Iter<'a, Value>;
80 fn into_iter(self) -> Self::IntoIter {
81 self.0.iter()
82 }
83}
84
85#[derive(Default, Debug, Clone, PartialEq)]
91pub struct Variadic<T>(Vec<T>);
92
93impl<T> Variadic<T> {
94 pub const fn new() -> Variadic<T> {
96 Variadic(Vec::new())
97 }
98
99 pub fn with_capacity(capacity: usize) -> Variadic<T> {
101 Variadic(Vec::with_capacity(capacity))
102 }
103}
104
105impl<T> Deref for Variadic<T> {
106 type Target = Vec<T>;
107 fn deref(&self) -> &Self::Target {
108 &self.0
109 }
110}
111
112impl<T> DerefMut for Variadic<T> {
113 fn deref_mut(&mut self) -> &mut Self::Target {
114 &mut self.0
115 }
116}
117
118impl<T> From<Vec<T>> for Variadic<T> {
119 fn from(vec: Vec<T>) -> Self {
120 Variadic(vec)
121 }
122}
123
124impl<T> From<Variadic<T>> for Vec<T> {
125 fn from(v: Variadic<T>) -> Self {
126 v.0
127 }
128}
129
130impl<T> FromIterator<T> for Variadic<T> {
131 fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
132 Variadic(Vec::from_iter(iter))
133 }
134}
135
136impl<T> IntoIterator for Variadic<T> {
137 type Item = T;
138 type IntoIter = std::vec::IntoIter<T>;
139 fn into_iter(self) -> Self::IntoIter {
140 self.0.into_iter()
141 }
142}