Skip to main content

DataLayer

Trait DataLayer 

Source
pub trait DataLayer<R: Resource>:
    Debug
    + Send
    + Sync
    + 'static {
    // Required methods
    fn create(
        &self,
        resource: R,
    ) -> impl Future<Output = Result<R, CreateError>> + Send;
    fn read(
        &self,
        primary_key: &R::PrimaryKey,
    ) -> impl Future<Output = Result<R, ReadError>> + Send;
    fn update(
        &self,
        resource: R,
    ) -> impl Future<Output = Result<(), UpdateError>> + Send;
    fn destroy(
        &self,
        primary_key: &R::PrimaryKey,
    ) -> impl Future<Output = Result<R, DestroyError>> + Send;
}
Expand description

Persistence backend for a specific resource type.

The trait is parameterized on R so that different data layers can impose different bounds on the resources they support. For example, InMemoryDataLayer has a blanket impl for all R: Resource, while a SQLite data layer can additionally require R: SqlResource.

Required Methods§

Source

fn create( &self, resource: R, ) -> impl Future<Output = Result<R, CreateError>> + Send

Persist a new resource and return the stored version.

The returned resource may differ from the input when the data layer provides server-generated values (e.g. autoincrement primary keys).

Source

fn read( &self, primary_key: &R::PrimaryKey, ) -> impl Future<Output = Result<R, ReadError>> + Send

Source

fn update( &self, resource: R, ) -> impl Future<Output = Result<(), UpdateError>> + Send

Source

fn destroy( &self, primary_key: &R::PrimaryKey, ) -> impl Future<Output = Result<R, DestroyError>> + Send

Remove a resource by primary key, returning the deleted resource.

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§

Source§

impl<R: Resource + 'static> DataLayer<R> for InMemoryDataLayer