hit_data/model/
model_field.rs1use crate::model::Model;
2use crate::object_data::ObjectValue;
3use crate::HitError;
4use crate::{errors::ValidationError, model::validators::ValidatorContext};
5use linked_hash_map::LinkedHashMap;
6use mopa;
7use std::cell::RefCell;
8use std::rc::Rc;
9
10pub trait ModelField: mopa::Any {
11 fn get_name(&self) -> String;
12 fn validate(
13 &self,
14 value: &ObjectValue,
15 context: &ValidatorContext,
16 ) -> Result<Option<Vec<ValidationError>>, HitError>;
17 fn accepts_for_set(&self, value: &ObjectValue, context: &ValidatorContext) -> bool;
18 fn accepts_model(&self, model: &Model) -> bool;
19 fn is_vec_reference(&self) -> bool;
20 fn is_vec_subobject(&self) -> bool;
21 fn on_kernel_init(&mut self, model_name: &str) -> Result<(), HitError>;
22}
23mopafy!(ModelField);
24
25pub type ModelFieldRef = Rc<RefCell<dyn ModelField>>;
26
27pub type Fields = LinkedHashMap<String, ModelFieldRef>;