Skip to main content

oak_csv/parser/
element_type.rs

1use crate::lexer::CsvTokenType;
2use oak_core::{ElementType, UniversalElementRole};
3use serde::{Deserialize, Serialize};
4
5/// CSV element type
6#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
7pub enum CsvElementType {
8    /// Source file (root)
9    SourceFile,
10    /// Record (row)
11    Record,
12    /// Field
13    Field,
14}
15
16impl ElementType for CsvElementType {
17    type Role = UniversalElementRole;
18
19    fn role(&self) -> Self::Role {
20        match self {
21            Self::SourceFile => UniversalElementRole::Root,
22            Self::Record => UniversalElementRole::Container,
23            Self::Field => UniversalElementRole::Value,
24        }
25    }
26}
27
28impl From<CsvTokenType> for CsvElementType {
29    fn from(token: CsvTokenType) -> Self {
30        match token {
31            _ => Self::Field,
32        }
33    }
34}