Skip to main content

Resource

Trait Resource 

Source
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§

Source

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).

Source

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.

Source

const PRIMARY_KEY_GENERATED: bool

Wether the primary key of the resource is generated

Required Associated Types§

Source

type PrimaryKey: Display + DeserializeOwned + Send + Sync

Primary key type of the resource. Usually the type of the id for the resource.

Source

type DataLayer: DataLayer<Self>

Data layer that the resource uses.

Required Methods§

Source

fn primary_key(&self) -> &Self::PrimaryKey

Mathos that returns the primary key of the resource

Provided Methods§

Source

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).

Source

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.

Implementors§