Skip to main content

Repository

Trait Repository 

Source
pub trait Repository<T>: Send + Sync
where 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§

Source

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.

Source

fn find_all( &self, ) -> Pin<Box<dyn Future<Output = Result<Vec<T>, RepoError>> + Send + '_>>

Return all entities of this type.

Source

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.

Source

fn update( &self, entity: T, ) -> Pin<Box<dyn Future<Output = Result<T, RepoError>> + Send + '_>>

Update an existing entity and return the updated value.

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

Source

fn delete( &self, id: <T as Entity>::Id, ) -> Pin<Box<dyn Future<Output = Result<(), RepoError>> + Send + '_>>

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§