atc_router/
schema.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use crate::ast::Type;
use std::collections::HashMap;

#[derive(Default)]
pub struct Schema {
    fields: HashMap<String, Type>,
}

impl Schema {
    pub fn type_of(&self, field: &str) -> Option<&Type> {
        self.fields.get(field).or_else(|| {
            self.fields
                .get(&format!("{}.*", &field[..field.rfind('.')?]))
        })
    }

    pub fn add_field(&mut self, field: &str, typ: Type) {
        self.fields.insert(field.to_string(), typ);
    }
}