Rohan Sircar
3 years ago
9 changed files with 125 additions and 84 deletions
-
5src/actions/users.rs
-
58src/errors/domain_error.rs
-
13src/main.rs
-
3src/models/errors.rs
-
20src/routes/auth.rs
-
66src/routes/users.rs
-
8src/services/user_service.rs
-
2src/utils.rs
-
34src/utils/ops.rs
@ -0,0 +1,34 @@ |
|||
use std::fmt::Display;
|
|||
|
|||
pub trait LogErrorResult<T, E> {
|
|||
fn log_err(self) -> Result<T, E>;
|
|||
}
|
|||
impl<T, E: Display> LogErrorResult<T, E> for Result<T, E> {
|
|||
fn log_err(self) -> Result<T, E> {
|
|||
self.map_err(|err| {
|
|||
error!("{}", err.to_string());
|
|||
err
|
|||
})
|
|||
}
|
|||
}
|
|||
|
|||
trait ResultOps<T, E> {
|
|||
fn tap<U, F: FnOnce(T) -> U>(self, op: F) -> Result<T, E>;
|
|||
fn tap_err<F, O: FnOnce(E) -> F>(self, op: O) -> Result<T, E>;
|
|||
}
|
|||
|
|||
impl<T: Clone, E: Clone> ResultOps<T, E> for Result<T, E> {
|
|||
fn tap<U, F: FnOnce(T) -> U>(self, op: F) -> Result<T, E> {
|
|||
self.map(|x| {
|
|||
op(x.clone());
|
|||
x
|
|||
})
|
|||
}
|
|||
|
|||
fn tap_err<F, O: FnOnce(E) -> F>(self, op: O) -> Result<T, E> {
|
|||
self.map_err(|err| {
|
|||
op(err.clone());
|
|||
err
|
|||
})
|
|||
}
|
|||
}
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue