atc-router 1.3.1

Versatile DSL based rule matching engine used by the Kong API Gateway
Documentation
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);
    }
}