pub trait DataLayer<R: Resource>:
Debug
+ Send
+ Sync
+ 'static {
// Required methods
fn create(&self, resource: R) -> impl Future<Output = Result<R>> + Send;
fn read(
&self,
primary_key: &R::PrimaryKey,
) -> impl Future<Output = Result<R>> + Send;
fn update(&self, resource: R) -> impl Future<Output = Result<()>> + Send;
fn destroy(
&self,
primary_key: &R::PrimaryKey,
) -> impl Future<Output = Result<R>> + 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§
Sourcefn create(&self, resource: R) -> impl Future<Output = Result<R>> + Send
fn create(&self, resource: R) -> impl Future<Output = Result<R>> + 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).
fn read( &self, primary_key: &R::PrimaryKey, ) -> impl Future<Output = Result<R>> + Send
fn update(&self, resource: R) -> impl Future<Output = Result<()>> + Send
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.