pub struct TypedError<E>(pub E);Available on crate feature
ws only.Expand description
A handler error which reaches the client as a typed value.
The wrapped error is encoded in the body format of the connection, and the
client decodes it back with web::Error::server_error (or
client::Error::server_error). Its fmt::Display text is sent along as
the message of the error, which is what a client that does not decode the
payload sees. See Errors for an example.
If the error cannot be encoded the client receives the message alone, as if it was a plain text error.
This deliberately does not implement fmt::Display itself, since that
would make it a text error. Use TypedError::get or the public field to
get at the error.
§Examples
use musli_web::ws::TypedError;
fn check(value: u32) -> Result<u32, TypedError<String>> {
if value == 0 {
// Converted with `From` by the question mark operator.
Err::<(), _>(String::from("Zero is not allowed"))?;
}
Ok(value)
}
let error = check(0).unwrap_err();
assert_eq!(error.get(), "Zero is not allowed");Tuple Fields§
§0: EImplementations§
Source§impl<E> TypedError<E>
impl<E> TypedError<E>
Trait Implementations§
Source§impl<E: Clone> Clone for TypedError<E>
impl<E: Clone> Clone for TypedError<E>
impl<E: Copy> Copy for TypedError<E>
Source§impl<E: Debug> Debug for TypedError<E>
impl<E: Debug> Debug for TypedError<E>
Source§impl<E: Default> Default for TypedError<E>
impl<E: Default> Default for TypedError<E>
impl<E: Eq> Eq for TypedError<E>
Source§impl<E> From<E> for TypedError<E>
impl<E> From<E> for TypedError<E>
Source§impl<E: Hash> Hash for TypedError<E>
impl<E: Hash> Hash for TypedError<E>
Source§impl<E: PartialEq> PartialEq for TypedError<E>
impl<E: PartialEq> PartialEq for TypedError<E>
Source§impl<E> ResponseError for TypedError<E>
impl<E> ResponseError for TypedError<E>
Source§fn fmt_message(&self, f: &mut Formatter<'_>) -> Result
fn fmt_message(&self, f: &mut Formatter<'_>) -> Result
Write the human readable message of the error. Read more
Source§fn encode_payload(&self, payload: ErrorPayload<'_>) -> Result<(), Error>
fn encode_payload(&self, payload: ErrorPayload<'_>) -> Result<(), Error>
Encode the typed payload of the error, if it has one, by calling
ErrorPayload::encode. Read moreimpl<E: PartialEq> StructuralPartialEq for TypedError<E>
Auto Trait Implementations§
impl<E> Freeze for TypedError<E>where
E: Freeze,
impl<E> RefUnwindSafe for TypedError<E>where
E: RefUnwindSafe,
impl<E> Send for TypedError<E>where
E: Send,
impl<E> Sync for TypedError<E>where
E: Sync,
impl<E> Unpin for TypedError<E>where
E: Unpin,
impl<E> UnsafeUnpin for TypedError<E>where
E: UnsafeUnpin,
impl<E> UnwindSafe for TypedError<E>where
E: UnwindSafe,
Blanket Implementations§
impl<Token, Builder, How> AllPropsFor<Builder, How> for Tokenwhere
Builder: Buildable<Token>,
<Builder as Buildable<Token>>::WrappedToken: HasAllProps<<Builder as Buildable<Token>>::Output, How>,
impl<Token, Builder, How> AllPropsFor<Builder, How> for Tokenwhere
Builder: Buildable<Token>,
<Builder as Buildable<Token>>::WrappedToken: HasAllProps<<Builder as Buildable<Token>>::Output, How>,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.impl<T> HasAllProps<(), T> for T
impl<T> HasAllProps<(), T> for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoPropValue<Option<T>> for T
impl<T> IntoPropValue<Option<T>> for T
Source§fn into_prop_value(self) -> Option<T>
fn into_prop_value(self) -> Option<T>
Convert
self to a value of a Properties struct.Source§impl<T> IntoPropValue<Option<T>> for T
impl<T> IntoPropValue<Option<T>> for T
Source§fn into_prop_value(self) -> Option<T>
fn into_prop_value(self) -> Option<T>
Convert
self to a value of a Properties struct.Source§impl<T> IntoPropValue<T> for T
impl<T> IntoPropValue<T> for T
Source§fn into_prop_value(self) -> T
fn into_prop_value(self) -> T
Convert
self to a value of a Properties struct.Source§impl<T> IntoPropValue<T> for T
impl<T> IntoPropValue<T> for T
Source§fn into_prop_value(self) -> T
fn into_prop_value(self) -> T
Convert
self to a value of a Properties struct.