Skip to main content

TypedError

Struct TypedError 

Source
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: E

Implementations§

Source§

impl<E> TypedError<E>

Source

pub const fn new(error: E) -> Self

Wrap an error.

§Examples
use musli_web::ws::TypedError;

let error = TypedError::new(42u32);
assert_eq!(error.into_inner(), 42);
Source

pub const fn get(&self) -> &E

Get a reference to the wrapped error.

Source

pub fn into_inner(self) -> E

Unwrap the error.

Trait Implementations§

Source§

impl<E: Clone> Clone for TypedError<E>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<E: Copy> Copy for TypedError<E>

Source§

impl<E: Debug> Debug for TypedError<E>

Source§

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

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

impl<E: Default> Default for TypedError<E>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<E: Eq> Eq for TypedError<E>

Source§

impl<E> From<E> for TypedError<E>

Source§

fn from(error: E) -> Self

Converts to this type from the input type.
Source§

impl<E: Hash> Hash for TypedError<E>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<E: PartialEq> PartialEq for TypedError<E>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<E> ResponseError for TypedError<E>
where E: 'static + Send + Display + EncodeBody,

Source§

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>

Encode the typed payload of the error, if it has one, by calling ErrorPayload::encode. Read more
Source§

impl<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§

Source§

impl<Token, Builder, How> AllPropsFor<Builder, How> for Token
where Builder: Buildable<Token>, <Builder as Buildable<Token>>::WrappedToken: HasAllProps<<Builder as Buildable<Token>>::Output, How>,

Source§

impl<Token, Builder, How> AllPropsFor<Builder, How> for Token
where Builder: Buildable<Token>, <Builder as Buildable<Token>>::WrappedToken: HasAllProps<<Builder as Buildable<Token>>::Output, How>,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> HasAllProps<(), T> for T

Source§

impl<T> HasAllProps<(), T> for T

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> IntoPropValue<Option<T>> for T

Source§

fn into_prop_value(self) -> Option<T>

Convert self to a value of a Properties struct.
Source§

impl<T> IntoPropValue<Option<T>> for T

Source§

fn into_prop_value(self) -> Option<T>

Convert self to a value of a Properties struct.
Source§

impl<T> IntoPropValue<T> for T

Source§

fn into_prop_value(self) -> T

Convert self to a value of a Properties struct.
Source§

impl<T> IntoPropValue<T> for T

Source§

fn into_prop_value(self) -> T

Convert self to a value of a Properties struct.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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