Skip to main content

ModelHooks

Trait ModelHooks 

Source
pub trait ModelHooks {
    // Provided methods
    fn before_model(_input: &mut Value, _ctx: &mut ValidationContext) { ... }
    fn before_field(
        _field: &str,
        _input: &mut Value,
        _ctx: &mut ValidationContext,
    ) { ... }
    fn after_fields(&self, _ctx: &mut ValidationContext) { ... }
    fn after_model(&self, _ctx: &mut ValidationContext) { ... }
    fn computed_fields(
        &self,
        _out: &mut Map<String, Value>,
        _opts: &DumpOptions,
    ) -> Result<(), DumpError> { ... }
    fn computed_schema(
        _properties: &mut Map<String, Value>,
        _registry: &mut SchemaRegistry,
    ) { ... }
    fn serialize_field(
        &self,
        _field: &str,
        value: Value,
    ) -> Result<Value, DumpError> { ... }
    fn serialize_model(&self, value: Value) -> Result<Value, DumpError> { ... }
}
Expand description

Hooks a model can provide. Every method defaults to doing nothing.

Provided Methods§

Source

fn before_model(_input: &mut Value, _ctx: &mut ValidationContext)

Model before-validators, run on the raw input object.

Source

fn before_field(_field: &str, _input: &mut Value, _ctx: &mut ValidationContext)

Field before-validators for the field whose Rust name is field, run on its raw input slot (location already set to the field).

Source

fn after_fields(&self, _ctx: &mut ValidationContext)

Field after-validators (each reports at its field’s location).

Source

fn after_model(&self, _ctx: &mut ValidationContext)

Model after-validators.

Source

fn computed_fields( &self, _out: &mut Map<String, Value>, _opts: &DumpOptions, ) -> Result<(), DumpError>

Insert computed fields into the serialized object.

§Errors

Serialization failures of computed values.

Source

fn computed_schema( _properties: &mut Map<String, Value>, _registry: &mut SchemaRegistry, )

Document computed fields (added as readOnly properties).

Source

fn serialize_field( &self, _field: &str, value: Value, ) -> Result<Value, DumpError>

Field serializer for the field whose Rust name is field.

§Errors

Serialization failures.

Source

fn serialize_model(&self, value: Value) -> Result<Value, DumpError>

Model serializer applied to the finished object.

§Errors

Serialization failures.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§