pub enum Model {
Root(ModelRoot),
EmbeddedStruct(EmbeddedStruct),
EmbeddedEnum(EmbeddedEnum),
}Expand description
A model in the application schema.
Models come in three flavors:
Model::Root– a top-level model backed by its own database table.Model::EmbeddedStruct– a struct whose fields are flattened into a parent model’s table.Model::EmbeddedEnum– an enum stored via a discriminant column plus optional per-variant data columns in the parent table.
§Examples
ⓘ
use toasty_core::schema::app::{Model, Schema};
let schema: Schema = /* built from derive macros */;
for model in schema.models() {
if model.is_root() {
println!("Root model: {}", model.name().upper_camel_case());
}
}Variants§
Root(ModelRoot)
A root model that maps to its own database table and can be queried directly.
EmbeddedStruct(EmbeddedStruct)
An embedded struct whose fields are flattened into its parent model’s table.
EmbeddedEnum(EmbeddedEnum)
An embedded enum stored as a discriminant column (plus optional per-variant data columns) in the parent table.
Implementations§
Source§impl Model
impl Model
Sourcepub fn is_root(&self) -> bool
pub fn is_root(&self) -> bool
Returns true if this is a root model (has a table and primary key)
Sourcepub fn is_embedded(&self) -> bool
pub fn is_embedded(&self) -> bool
Returns true if this is an embedded model (flattened into parent)
Sourcepub fn can_be_relation_target(&self) -> bool
pub fn can_be_relation_target(&self) -> bool
Returns true if this model can be the target of a relation
Sourcepub fn as_root(&self) -> Option<&ModelRoot>
pub fn as_root(&self) -> Option<&ModelRoot>
Returns the inner ModelRoot if this is a root model.
Sourcepub fn as_root_unwrap(&self) -> &ModelRoot
pub fn as_root_unwrap(&self) -> &ModelRoot
Sourcepub fn as_root_mut_unwrap(&mut self) -> &mut ModelRoot
pub fn as_root_mut_unwrap(&mut self) -> &mut ModelRoot
Sourcepub fn as_embedded_struct_unwrap(&self) -> &EmbeddedStruct
pub fn as_embedded_struct_unwrap(&self) -> &EmbeddedStruct
Returns a reference to the embedded struct data.
§Panics
Panics if this is not a Model::EmbeddedStruct.
Sourcepub fn as_embedded_enum_unwrap(&self) -> &EmbeddedEnum
pub fn as_embedded_enum_unwrap(&self) -> &EmbeddedEnum
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Model
impl RefUnwindSafe for Model
impl Send for Model
impl Sync for Model
impl Unpin for Model
impl UnwindSafe for Model
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more