use std::ops::Index;
use super::Literal;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Struct {
fields: Vec<Option<Literal>>,
}
impl Struct {
pub fn empty() -> Self {
Self { fields: Vec::new() }
}
pub fn iter(&self) -> impl ExactSizeIterator<Item = Option<&Literal>> {
self.fields.iter().map(|field| field.as_ref())
}
pub fn is_null_at_index(&self, index: usize) -> bool {
self.fields[index].is_none()
}
pub fn fields(&self) -> &[Option<Literal>] {
&self.fields
}
}
impl Index<usize> for Struct {
type Output = Option<Literal>;
fn index(&self, idx: usize) -> &Self::Output {
&self.fields[idx]
}
}
impl IntoIterator for Struct {
type Item = Option<Literal>;
type IntoIter = std::vec::IntoIter<Option<Literal>>;
fn into_iter(self) -> Self::IntoIter {
self.fields.into_iter()
}
}
impl FromIterator<Option<Literal>> for Struct {
fn from_iter<I: IntoIterator<Item = Option<Literal>>>(iter: I) -> Self {
Struct {
fields: iter.into_iter().collect(),
}
}
}