1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
use crate::value_parsing::{Parsed, RawValue}; use std::fmt::{Debug, Display}; use std::hash::Hash; pub trait Typer: Default + Clone + Debug + Send + Sync + 'static { type ColumnType: Display + Hash + Eq + Copy + Send + Sync + Debug + Default; type DatasetValue: DatasetValue<Self::ColumnType>; const COLUMN_TYPES: &'static [Self::ColumnType]; fn parse_as(&self, value: &RawValue, tag: Self::ColumnType) -> Parsed<Self::DatasetValue>; fn parse(&self, value: &RawValue) -> Parsed<Self::DatasetValue> { Self::COLUMN_TYPES .iter() .map(|tag| self.parse_as(value, *tag)) .find(|v| v.is_some()) .unwrap_or(Parsed::Invalid) } } pub trait DatasetValue<C>: Debug + Clone + PartialEq + Send + Sync { fn get_column_type(&self) -> C; }