Skip to main content

Repository

Trait Repository 

Source
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§

Source

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.

Source

fn find_all(&self) -> BoxFuture<'_, Result<Vec<T>, RepoError>>

Return all entities of this type.

Source

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.

Source

fn update(&self, entity: T) -> BoxFuture<'_, Result<T, RepoError>>

Update an existing entity and return the updated value.

Returns RepoError::NotFound if the entity does not exist.

Source

fn delete(&self, id: T::Id) -> BoxFuture<'_, Result<(), RepoError>>

Delete an entity by its unique identifier.

Returns RepoError::NotFound if the entity does not exist.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§