Trait Model

Source
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§

Source

const MODEL_NAME: &'static str

Model name.

Provided Associated Constants§

Source

const ITEM_NAME: (&'static str, &'static str) = _

Data item name.

Provided Methods§

Source

fn new() -> Self

Creates a new instance.

Source

fn model_name() -> &'static str

Returns the model name.

Source

fn read_map(&mut self, data: &Map) -> Validation

Updates the model using the json object and returns the validation result.

Source

fn try_from_map(data: Map) -> Result<Self, Error>

Attempts to construct a model from a json object.

Source

fn try_from_avro_record(data: Record) -> Result<Self, Error>

Attempts to construct a model from an Avro record.

Source

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.

Source

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.

Source

fn data_item(value: impl Into<JsonValue>) -> Map

Constructs an instance of Map for the data item.

Source

fn data_items<T: Into<JsonValue>>(values: Vec<T>) -> Map

Constructs an instance of Map for the data items.

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.

Implementors§