use crate::{column::Column, types::Type};
mod sealed {
pub trait Sealed {}
}
#[doc(hidden)]
pub trait RowIndexAndType: sealed::Sealed + Copy {
fn _from_columns(self, col: &[Column]) -> Option<(usize, &Type)>;
}
impl sealed::Sealed for usize {}
impl RowIndexAndType for usize {
#[inline]
fn _from_columns(self, col: &[Column]) -> Option<(usize, &Type)> {
col.get(self).map(|col| (self, col.r#type()))
}
}
impl sealed::Sealed for &str {}
impl RowIndexAndType for &str {
#[inline]
fn _from_columns(self, col: &[Column]) -> Option<(usize, &Type)> {
col.iter()
.enumerate()
.find_map(|(idx, col)| col.name().eq(self).then(|| (idx, col.r#type())))
.or_else(|| {
col.iter()
.enumerate()
.find_map(|(idx, col)| col.name().eq_ignore_ascii_case(self).then(|| (idx, col.r#type())))
})
}
}