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 trait DefaultRepository<'f> {
fn add(&'f mut self, r: Robot) -> TraitFuture<'f, Result<i64, HandlingError>>;
fn get_by_id(&'f mut self, id: i64) -> TraitFuture<'f, Result<Robot, HandlingError>>;
fn update(&'f mut self, r: Robot) -> TraitFuture<Result<(), HandlingError>>;
fn delete(&'f mut self, id: i64) -> TraitFuture<Result<(), HandlingError>>;
pub trait DefaultRepository<'c> {
fn add(&'c mut self, r: Robot) -> TraitFuture<Result<i64, HandlingError>>;
fn get_by_id(&'c mut self, id: i64) -> TraitFuture<Result<Robot, HandlingError>>;
fn update(&'c mut self, r: Robot) -> TraitFuture<Result<(), HandlingError>>;
fn delete(&'c mut self, id: i64) -> TraitFuture<Result<(), HandlingError>>;
}
pub async fn add<'a>(
repo: &'a mut impl DefaultRepository<'a>,
pub async fn add<'c>(
repo: &'c mut impl DefaultRepository<'c>,
r: Robot,
) -> Result<i64, HandlingError> {
repo.add(r).await
}
pub async fn update<'a>(
repo: &'a mut impl DefaultRepository<'a>,
pub async fn update<'c>(
repo: &'c mut impl DefaultRepository<'c>,
r: Robot,
) -> Result<(), HandlingError> {
repo.update(r).await
}
pub async fn delete<'a>(
repo: &'a mut impl DefaultRepository<'a>,
pub async fn delete<'c>(
repo: &'c mut impl DefaultRepository<'c>,
id: i64,
) -> Result<(), HandlingError> {
repo.delete(id).await

Loading…
Cancel
Save