use query_structure::{FieldArity, TypeIdentifier};
#[derive(Clone, Debug, Copy)]
pub(crate) struct ColumnMetadata<'a> {
identifier: &'a TypeIdentifier,
name: Option<&'a str>,
arity: FieldArity,
}
impl<'a> ColumnMetadata<'a> {
fn new(identifier: &'a TypeIdentifier, arity: FieldArity) -> Self {
Self {
identifier,
name: None,
arity,
}
}
fn set_name(mut self, name: &'a str) -> Self {
self.name = Some(name);
self
}
pub fn identifier(self) -> &'a TypeIdentifier {
self.identifier
}
pub fn name(self) -> Option<&'a str> {
self.name
}
pub fn arity(self) -> FieldArity {
self.arity
}
}
pub(crate) fn create<'a, T>(field_names: &'a [T], idents: &'a [(TypeIdentifier, FieldArity)]) -> Vec<ColumnMetadata<'a>>
where
T: AsRef<str>,
{
assert_eq!(field_names.len(), idents.len());
idents
.iter()
.zip(field_names.iter())
.map(|((identifier, arity), name)| ColumnMetadata::new(identifier, *arity).set_name(name.as_ref()))
.collect()
}
pub(crate) fn create_anonymous(idents: &[(TypeIdentifier, FieldArity)]) -> Vec<ColumnMetadata<'_>> {
idents
.iter()
.map(|(identifier, arity)| ColumnMetadata::new(identifier, *arity))
.collect()
}