Simplify lifetime usage of default repository

develop
cahe 5 years ago
parent 79bbed4fe0
commit 54522ba8c6

@ -6,29 +6,29 @@ pub struct Robot {
pub name: String, pub name: String,
} }
pub trait DefaultRepository<'f> { pub trait DefaultRepository<'c> {
fn add(&'f mut self, r: Robot) -> TraitFuture<'f, Result<i64, HandlingError>>; fn add(&'c mut self, r: Robot) -> TraitFuture<Result<i64, HandlingError>>;
fn get_by_id(&'f mut self, id: i64) -> TraitFuture<'f, Result<Robot, HandlingError>>; fn get_by_id(&'c mut self, id: i64) -> TraitFuture<Result<Robot, HandlingError>>;
fn update(&'f mut self, r: Robot) -> TraitFuture<Result<(), HandlingError>>; fn update(&'c mut self, r: Robot) -> TraitFuture<Result<(), HandlingError>>;
fn delete(&'f mut self, id: i64) -> TraitFuture<Result<(), HandlingError>>; fn delete(&'c mut self, id: i64) -> TraitFuture<Result<(), HandlingError>>;
} }
pub async fn add<'a>( pub async fn add<'c>(
repo: &'a mut impl DefaultRepository<'a>, repo: &'c mut impl DefaultRepository<'c>,
r: Robot, r: Robot,
) -> Result<i64, HandlingError> { ) -> Result<i64, HandlingError> {
repo.add(r).await repo.add(r).await
} }
pub async fn update<'a>( pub async fn update<'c>(
repo: &'a mut impl DefaultRepository<'a>, repo: &'c mut impl DefaultRepository<'c>,
r: Robot, r: Robot,
) -> Result<(), HandlingError> { ) -> Result<(), HandlingError> {
repo.update(r).await repo.update(r).await
} }
pub async fn delete<'a>( pub async fn delete<'c>(
repo: &'a mut impl DefaultRepository<'a>, repo: &'c mut impl DefaultRepository<'c>,
id: i64, id: i64,
) -> Result<(), HandlingError> { ) -> Result<(), HandlingError> {
repo.delete(id).await repo.delete(id).await

Loading…
Cancel
Save