pub trait Resource:
Serialize
+ DeserializeOwned
+ Send
+ Sync
+ Clone
+ 'static {
type PrimaryKey: Display + DeserializeOwned + Send + Sync;
type DataLayer: DataLayer<Self>;
const NAME: &'static [&'static str];
const RESOURCE_NAME: &'static str;
const PRIMARY_KEY_GENERATED: bool;
// Required method
fn primary_key(&self) -> &Self::PrimaryKey;
// Provided methods
fn before_create(&mut self) { ... }
fn before_update(&mut self) { ... }
}Expand description
Marker trait for a resource.
Required Associated Constants§
Sourceconst NAME: &'static [&'static str]
const NAME: &'static [&'static str]
Name with namespace of the resource. Each part of the array is a segment in the name (i.e. MyApp.Blog.Post).
Sourceconst RESOURCE_NAME: &'static str
const RESOURCE_NAME: &'static str
Dot-joined resource name (e.g. "MyApp.Blog.Post").
Generated by the resource! macro as a string literal — no runtime
allocation or leak() required.
Sourceconst PRIMARY_KEY_GENERATED: bool
const PRIMARY_KEY_GENERATED: bool
Wether the primary key of the resource is generated
Required Associated Types§
Sourcetype PrimaryKey: Display + DeserializeOwned + Send + Sync
type PrimaryKey: Display + DeserializeOwned + Send + Sync
Primary key type of the resource. Usually the type of the id for the resource.
Required Methods§
Sourcefn primary_key(&self) -> &Self::PrimaryKey
fn primary_key(&self) -> &Self::PrimaryKey
Mathos that returns the primary key of the resource
Provided Methods§
Sourcefn before_create(&mut self)
fn before_create(&mut self)
Lifecycle hook called on every create action, after the resource is
built from input but before persistence. Override to mutate the
resource (e.g. set created_at timestamps).
Sourcefn before_update(&mut self)
fn before_update(&mut self)
Lifecycle hook called on every update action, after
apply_update_input but before persistence. Override to mutate the
resource (e.g. set updated_at timestamps).
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.