pub trait Model:
Default
+ Serialize
+ DeserializeOwned {
const MODEL_NAME: &'static str;
const ITEM_NAME: (&'static str, &'static str) = _;
// Provided methods
fn new() -> Self { ... }
fn model_name() -> &'static str { ... }
fn read_map(&mut self, data: &Map) -> Validation { ... }
fn try_from_map(data: Map) -> Result<Self, Error> { ... }
fn try_from_avro_record(data: Record) -> Result<Self, Error> { ... }
fn into_map(self) -> Map { ... }
fn into_avro_record(self) -> Record { ... }
fn data_item(value: impl Into<JsonValue>) -> Map { ... }
fn data_items<T: Into<JsonValue>>(values: Vec<T>) -> Map { ... }
}
Expand description
General data model.
This trait can be derived by zino_derive::Model
.
Required Associated Constants§
Sourceconst MODEL_NAME: &'static str
const MODEL_NAME: &'static str
Model name.
Provided Associated Constants§
Provided Methods§
Sourcefn model_name() -> &'static str
fn model_name() -> &'static str
Returns the model name.
Sourcefn read_map(&mut self, data: &Map) -> Validation
fn read_map(&mut self, data: &Map) -> Validation
Updates the model using the json object and returns the validation result.
Sourcefn try_from_map(data: Map) -> Result<Self, Error>
fn try_from_map(data: Map) -> Result<Self, Error>
Attempts to construct a model from a json object.
Sourcefn try_from_avro_record(data: Record) -> Result<Self, Error>
fn try_from_avro_record(data: Record) -> Result<Self, Error>
Attempts to construct a model from an Avro record.
Sourcefn into_map(self) -> Map
fn into_map(self) -> Map
Consumes the model and returns as a json object.
§Panics
It will panic if the model cann’t be converted to a json object.
Sourcefn into_avro_record(self) -> Record
fn into_avro_record(self) -> Record
Consumes the model and returns as an Avro record.
§Panics
It will panic if the model cann’t be converted to an Avro record.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.