pub trait Repository<T: Entity>: Send + Sync {
// Required methods
fn find_by_id(&self, id: T::Id) -> BoxFuture<'_, Result<T, RepoError>>;
fn find_all(&self) -> BoxFuture<'_, Result<Vec<T>, RepoError>>;
fn create(&self, entity: T) -> BoxFuture<'_, Result<T, RepoError>>;
fn update(&self, entity: T) -> BoxFuture<'_, Result<T, RepoError>>;
fn delete(&self, id: T::Id) -> BoxFuture<'_, Result<(), RepoError>>;
}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::Id) -> BoxFuture<'_, Result<T, RepoError>>
fn find_by_id(&self, id: T::Id) -> BoxFuture<'_, Result<T, RepoError>>
Find an entity by its unique identifier.
Returns RepoError::NotFound if no entity with the given ID exists.
Sourcefn find_all(&self) -> BoxFuture<'_, Result<Vec<T>, RepoError>>
fn find_all(&self) -> BoxFuture<'_, Result<Vec<T>, RepoError>>
Return all entities of this type.
Sourcefn create(&self, entity: T) -> BoxFuture<'_, Result<T, RepoError>>
fn create(&self, entity: T) -> BoxFuture<'_, Result<T, RepoError>>
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".