pub enum RespResult<T, E> {
Success(T),
Err(E),
}Expand description
resp result for more flexible control the response body
Resultwill become500using as web framework response type whenErr(_), the action usually not I expect- using non-Result type as web framework response type cannot using
?, the code will fill withif letormatch
that why I need a RespResult which can
- control respond code or other message when it become
RespResult::Err, not always500 - impl the
Trythus can using friendly?to simplify code
note: because the
Trynot stable yet, this crate needNightlyrust
Variants§
Success(T)
the respond is success with response body T
Err(E)
the respond is failure with response error E
Implementations§
Source§impl<T, E> RespResult<T, E>
impl<T, E> RespResult<T, E>
Sourcepub fn flag_ok(
data: T,
flags: impl Into<ExtraFlags>,
) -> RespResult<FlagWrap<T>, E>
pub fn flag_ok( data: T, flags: impl Into<ExtraFlags>, ) -> RespResult<FlagWrap<T>, E>
create a RespResult::Success with flags
Sourcepub fn with_flags(
self,
flags: impl Into<ExtraFlags>,
) -> RespResult<FlagWrap<T>, E>
pub fn with_flags( self, flags: impl Into<ExtraFlags>, ) -> RespResult<FlagWrap<T>, E>
covert a RespResult::<T, E> into RespResult<FlagWrap<T>, E> with provide flags
Source§impl<T, E> RespResult<T, E>
impl<T, E> RespResult<T, E>
Sourcepub fn map<N, F>(self, f: F) -> RespResult<N, E>where
F: FnOnce(T) -> N,
pub fn map<N, F>(self, f: F) -> RespResult<N, E>where
F: FnOnce(T) -> N,
map currently T into N,
this method is similar to the same name method of Result
Sourcepub fn map_err<N, F>(self, f: F) -> RespResult<T, N>where
F: FnOnce(E) -> N,
pub fn map_err<N, F>(self, f: F) -> RespResult<T, N>where
F: FnOnce(E) -> N,
map currently E into N,
this method is similar to the same name method of Result
Sourcepub fn and_then<N, F>(self, f: F) -> RespResult<N, E>where
F: FnOnce(T) -> RespResult<N, E>,
pub fn and_then<N, F>(self, f: F) -> RespResult<N, E>where
F: FnOnce(T) -> RespResult<N, E>,
this method is similar to the same name method of Result
Sourcepub fn or_else<N, F>(self, f: F) -> RespResult<T, N>where
F: FnOnce(E) -> RespResult<T, N>,
pub fn or_else<N, F>(self, f: F) -> RespResult<T, N>where
F: FnOnce(E) -> RespResult<T, N>,
this method is similar to the same name method of Result
Source§impl<T, E> RespResult<T, E>
impl<T, E> RespResult<T, E>
Sourcepub fn ok(data: T) -> Self
pub fn ok(data: T) -> Self
create an success RespResult
Sourcepub fn err(err: E) -> Selfwhere
E: RespError,
pub fn err(err: E) -> Selfwhere
E: RespError,
create an error RespResult
Trait Implementations§
Source§impl<T, R> Fallible for RespResult<T, R>
impl<T, R> Fallible for RespResult<T, R>
Source§impl<T, E> From<RespResult<T, E>> for RespResult<FlagWrap<T>, E>
impl<T, E> From<RespResult<T, E>> for RespResult<FlagWrap<T>, E>
Source§fn from(inner: RespResult<T, E>) -> Self
fn from(inner: RespResult<T, E>) -> Self
Converts to this type from the input type.
Source§impl<T, E, F> FromResidual<RespResult<Infallible, E>> for Result<T, F>where
F: From<E>,
impl<T, E, F> FromResidual<RespResult<Infallible, E>> for Result<T, F>where
F: From<E>,
Source§fn from_residual(residual: RespResult<Infallible, E>) -> Self
fn from_residual(residual: RespResult<Infallible, E>) -> Self
🔬This is a nightly-only experimental API. (
try_trait_v2)Constructs the type from a compatible
Residual type. Read moreSource§impl<T, E, Ei> FromResidual<RespResult<Infallible, Ei>> for RespResult<T, E>where
E: From<Ei>,
impl<T, E, Ei> FromResidual<RespResult<Infallible, Ei>> for RespResult<T, E>where
E: From<Ei>,
Source§fn from_residual(residual: RespResult<Infallible, Ei>) -> Self
fn from_residual(residual: RespResult<Infallible, Ei>) -> Self
🔬This is a nightly-only experimental API. (
try_trait_v2)Constructs the type from a compatible
Residual type. Read moreSource§impl<T, E, F> FromResidual<Result<Infallible, E>> for RespResult<T, F>where
F: From<E>,
impl<T, E, F> FromResidual<Result<Infallible, E>> for RespResult<T, F>where
F: From<E>,
Source§fn from_residual(residual: Result<Infallible, E>) -> Self
fn from_residual(residual: Result<Infallible, E>) -> Self
🔬This is a nightly-only experimental API. (
try_trait_v2)Constructs the type from a compatible
Residual type. Read moreSource§impl<E, T> IntoRespResult<T, E> for RespResult<T, E>where
E: RespError,
impl<E, T> IntoRespResult<T, E> for RespResult<T, E>where
E: RespError,
fn into_rresult(self) -> RespResult<T, E>
Source§impl<T, E> IntoResponse for RespResult<T, E>where
T: RespBody,
E: RespError,
impl<T, E> IntoResponse for RespResult<T, E>where
T: RespBody,
E: RespError,
Source§fn into_response(self) -> Response
fn into_response(self) -> Response
Create a response.
Source§impl<T, E: RespError> Try for RespResult<T, E>
impl<T, E: RespError> Try for RespResult<T, E>
Source§type Output = T
type Output = T
🔬This is a nightly-only experimental API. (
try_trait_v2)The type of the value produced by
? when not short-circuiting.Source§type Residual = RespResult<Infallible, E>
type Residual = RespResult<Infallible, E>
🔬This is a nightly-only experimental API. (
try_trait_v2)The type of the value passed to
FromResidual::from_residual
as part of ? when short-circuiting. Read moreSource§fn from_output(output: Self::Output) -> Self
fn from_output(output: Self::Output) -> Self
🔬This is a nightly-only experimental API. (
try_trait_v2)Constructs the type from its
Output type. Read moreSource§fn branch(self) -> ControlFlow<Self::Residual, Self::Output>
fn branch(self) -> ControlFlow<Self::Residual, Self::Output>
🔬This is a nightly-only experimental API. (
try_trait_v2)Used in
? to decide whether the operator should produce a value
(because this returned ControlFlow::Continue)
or propagate a value back to the caller
(because this returned ControlFlow::Break). Read moreAuto Trait Implementations§
impl<T, E> Freeze for RespResult<T, E>
impl<T, E> RefUnwindSafe for RespResult<T, E>where
T: RefUnwindSafe,
E: RefUnwindSafe,
impl<T, E> Send for RespResult<T, E>
impl<T, E> Sync for RespResult<T, E>
impl<T, E> Unpin for RespResult<T, E>
impl<T, E> UnwindSafe for RespResult<T, E>where
T: UnwindSafe,
E: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more