Skip to main content

Model

Trait Model 

Source
pub trait Model:
    Attributes
    + ModelNaming
    + Conversion
    + Serialization
    + Sized
    + Send
    + Sync {
    // Required methods
    fn new() -> Self;
    fn errors(&self) -> &Errors;
    fn errors_mut(&mut self) -> &mut Errors;

    // Provided methods
    fn initialize(attrs: HashMap<String, Value>) -> Result<Self, AttributeError> { ... }
    fn is_valid(&self) -> bool { ... }
    fn is_invalid(&self) -> bool { ... }
    fn validate(&mut self) -> bool { ... }
}
Expand description

The minimum viable model interface shared by RustRails model types.

Required Methods§

Source

fn new() -> Self

Creates a new instance with default values.

Source

fn errors(&self) -> &Errors

Returns the model’s current error collection.

Source

fn errors_mut(&mut self) -> &mut Errors

Returns the mutable error collection for validation updates.

Provided Methods§

Source

fn initialize(attrs: HashMap<String, Value>) -> Result<Self, AttributeError>

Creates a new instance and applies the provided attributes.

Source

fn is_valid(&self) -> bool

Returns true when the model considers itself valid.

Source

fn is_invalid(&self) -> bool

Returns true when the model considers itself invalid.

Source

fn validate(&mut self) -> bool

Validates the model and updates its error collection.

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§