pub trait Repository<T>: Send + Syncwhere
T: Entity,{
// Required methods
fn find_by_id(
&self,
id: <T as Entity>::Id,
) -> Pin<Box<dyn Future<Output = Result<T, RepoError>> + Send + '_>>;
fn find_all(
&self,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, RepoError>> + Send + '_>>;
fn create(
&self,
entity: T,
) -> Pin<Box<dyn Future<Output = Result<T, RepoError>> + Send + '_>>;
fn update(
&self,
entity: T,
) -> Pin<Box<dyn Future<Output = Result<T, RepoError>> + Send + '_>>;
fn delete(
&self,
id: <T as Entity>::Id,
) -> Pin<Box<dyn Future<Output = Result<(), RepoError>> + Send + '_>>;
}Expand description
Core CRUD repository trait for a given entity type.
Provides the standard create, read, update, and delete operations.
Implementations should map persistence-layer errors to RepoError.
This trait is object-safe, enabling dynamic dispatch via dyn Repository<T>.
Required Methods§
Sourcefn find_by_id(
&self,
id: <T as Entity>::Id,
) -> Pin<Box<dyn Future<Output = Result<T, RepoError>> + Send + '_>>
fn find_by_id( &self, id: <T as Entity>::Id, ) -> Pin<Box<dyn Future<Output = Result<T, RepoError>> + Send + '_>>
Find an entity by its unique identifier.
Returns RepoError::NotFound if no entity with the given ID exists.
Sourcefn find_all(
&self,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, RepoError>> + Send + '_>>
fn find_all( &self, ) -> Pin<Box<dyn Future<Output = Result<Vec<T>, RepoError>> + Send + '_>>
Return all entities of this type.
Sourcefn create(
&self,
entity: T,
) -> Pin<Box<dyn Future<Output = Result<T, RepoError>> + Send + '_>>
fn create( &self, entity: T, ) -> Pin<Box<dyn Future<Output = Result<T, RepoError>> + Send + '_>>
Persist a new entity and return the created value.
Returns RepoError::Conflict if a unique constraint is violated.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".