Skip to main content

cinderblock_core/data_layer/
mod.rs

1use crate::Resource;
2
3pub mod in_memory;
4
5/// Persistence backend for a specific resource type.
6///
7/// The trait is parameterized on `R` so that different data layers can
8/// impose different bounds on the resources they support. For example,
9/// `InMemoryDataLayer` has a blanket impl for all `R: Resource`, while
10/// a SQLite data layer can additionally require `R: SqlResource`.
11pub trait DataLayer<R: Resource>: std::fmt::Debug + Send + Sync + 'static {
12    fn create(&self, resource: R) -> impl Future<Output = crate::Result<()>> + Send;
13
14    fn read(&self, primary_key: &R::PrimaryKey) -> impl Future<Output = crate::Result<R>> + Send;
15
16    fn update(&self, resource: R) -> impl Future<Output = crate::Result<()>> + Send;
17
18    /// Remove a resource by primary key, returning the deleted resource.
19    fn destroy(&self, primary_key: &R::PrimaryKey)
20    -> impl Future<Output = crate::Result<R>> + Send;
21}