pub trait FormModel: Send + Sync {
// Required methods
fn field_names() -> Vec<String>;
fn get_field(&self, name: &str) -> Option<Value>;
fn set_field(&mut self, name: &str, value: Value) -> Result<(), String>;
fn save(&mut self) -> Result<(), String>;
// Provided methods
fn field_type(_name: &str) -> Option<FieldType> { ... }
fn validate(&self) -> Result<(), Vec<String>> { ... }
fn to_choice_label(&self) -> String { ... }
fn to_choice_value(&self) -> String { ... }
}Expand description
Trait for models that can be used with ModelForm
This trait is specifically for form models. For ORM models, use reinhardt_db::orm::Model.
Required Methods§
Sourcefn field_names() -> Vec<String>
fn field_names() -> Vec<String>
Get the model’s field names
Provided Methods§
Sourcefn field_type(_name: &str) -> Option<FieldType>
fn field_type(_name: &str) -> Option<FieldType>
Sourcefn validate(&self) -> Result<(), Vec<String>>
fn validate(&self) -> Result<(), Vec<String>>
Run model-level (cross-field) validation hook.
This is an opt-in extension point invoked by ModelForm::is_valid
after per-field validation has already succeeded. The default
implementation intentionally performs no extra validation and returns
Ok(()); per-field validation is fully handled by the form’s
crate::Form::is_valid pipeline.
Implementers SHOULD override this method when they need cross-field invariants (e.g. “end_date must be after start_date”) that cannot be expressed at the individual field level.
Returns Ok(()) when the model passes all cross-field invariants, or
Err(messages) with one or more human-readable error messages.
Sourcefn to_choice_label(&self) -> String
fn to_choice_label(&self) -> String
Sourcefn to_choice_value(&self) -> String
fn to_choice_value(&self) -> String
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".