Enum RespResult

Source
pub enum RespResult<T, E> {
    Success(T),
    Err(E),
}
Expand description

resp result for more flexible control the response body

  • Result will become 500 using as web framework response type when Err(_), the action usually not I expect
  • using non-Result type as web framework response type cannot using ?, the code will fill with if let or match

that why I need a RespResult which can

  • control respond code or other message when it become RespResult::Err, not always 500
  • impl the Try thus can using friendly ? to simplify code

note: because the Try not stable yet, this crate need Nightly rust

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>

Source

pub fn flag_ok( data: T, flags: impl Into<ExtraFlags>, ) -> RespResult<FlagWrap<T>, E>

create a RespResult::Success with flags

Source

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>

Source

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

Source

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

Source

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

Source

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>

Source

pub fn ok(data: T) -> Self

create an success RespResult

Source

pub fn err(err: E) -> Self
where E: RespError,

create an error RespResult

Trait Implementations§

Source§

impl<T: Debug, E: RespError> Debug for RespResult<T, E>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Display, E: RespError> Display for RespResult<T, E>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, R> Fallible for RespResult<T, R>

Source§

type Success = T

Source§

type Failure = R

Source§

fn to_result(self) -> Result<<Self as Fallible>::Success, Self::Failure>

Source§

impl<T, E> From<RespResult<T, E>> for RespResult<FlagWrap<T>, E>

Source§

fn from(inner: RespResult<T, E>) -> Self

Converts to this type from the input type.
Source§

impl<T, E> From<Result<T, E>> for RespResult<T, E>
where E: RespError,

Source§

fn from(r: Result<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>,

Source§

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 more
Source§

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

🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from a compatible Residual type. Read more
Source§

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

🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from a compatible Residual type. Read more
Source§

impl<E, T> IntoRespResult<T, E> for RespResult<T, E>
where E: RespError,

Source§

impl<T, E> IntoResponse for RespResult<T, E>
where T: RespBody, E: RespError,

Source§

fn into_response(self) -> Response

Create a response.
Source§

impl<T, E: RespError> Try for RespResult<T, E>

Source§

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>

🔬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 more
Source§

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 more
Source§

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 more

Auto Trait Implementations§

§

impl<T, E> Freeze for RespResult<T, E>
where T: Freeze, E: Freeze,

§

impl<T, E> RefUnwindSafe for RespResult<T, E>

§

impl<T, E> Send for RespResult<T, E>
where T: Send, E: Send,

§

impl<T, E> Sync for RespResult<T, E>
where T: Sync, E: Sync,

§

impl<T, E> Unpin for RespResult<T, E>
where T: Unpin, E: Unpin,

§

impl<T, E> UnwindSafe for RespResult<T, E>
where T: UnwindSafe, E: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,