use super::Value;
#[derive(Clone, Debug, Default, PartialEq)]
pub struct Values(pub Vec<Value>);
impl Values {
#[must_use]
pub fn new() -> Self {
Self(Vec::new())
}
#[must_use]
pub fn with_capacity(capacity: usize) -> Self {
Self(Vec::with_capacity(capacity))
}
#[must_use]
pub fn len(&self) -> usize {
self.0.len()
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
pub fn push(&mut self, value: Value) -> usize {
self.0.push(value);
self.0.len()
}
pub fn iter(&self) -> impl Iterator<Item = &Value> {
self.0.iter()
}
#[must_use]
pub fn into_inner(self) -> Vec<Value> {
self.0
}
}
impl IntoIterator for Values {
type Item = Value;
type IntoIter = std::vec::IntoIter<Value>;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}
impl<'a> IntoIterator for &'a Values {
type Item = &'a Value;
type IntoIter = std::slice::Iter<'a, Value>;
fn into_iter(self) -> Self::IntoIter {
self.0.iter()
}
}
impl From<Vec<Value>> for Values {
fn from(values: Vec<Value>) -> Self {
Self(values)
}
}
impl From<Values> for Vec<Value> {
fn from(values: Values) -> Self {
values.0
}
}
impl std::ops::Deref for Values {
type Target = [Value];
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl std::ops::Index<usize> for Values {
type Output = Value;
fn index(&self, index: usize) -> &Self::Output {
&self.0[index]
}
}