Trait dioxus::prelude::Throw

source ·
pub trait Throw<S = ()>: Sized {
    type Out;

    // Required method
    fn throw(self) -> Option<Self::Out>;

    // Provided method
    fn throw_with<D>(self, e: impl FnOnce() -> D) -> Option<Self::Out>
       where D: Debug + 'static { ... }
}
Expand description

A trait to allow results to be thrown upwards to the nearest Error Boundary

The canonical way of using this trait is to throw results from hooks, aborting rendering through question mark syntax. The throw method returns an option that evaluates to None if there is an error, injecting the error to the nearest error boundary.

If the value is Ok, then throw returns the value, not aborting the rendering process.

The call stack is saved for this component and provided to the error boundary

#[component]
fn app(count: String) -> Element {
    let id: i32 = count.parse().throw()?;

    rsx! {
        div { "Count {}" }
    }
}

Required Associated Types§

source

type Out

The value that will be returned in if the given value is Ok.

Required Methods§

source

fn throw(self) -> Option<Self::Out>

Returns an option that evaluates to None if there is an error, injecting the error to the nearest error boundary.

If the value is Ok, then throw returns the value, not aborting the rendering process.

The call stack is saved for this component and provided to the error boundary

Note that you can also manually throw errors using the throw method on ScopeState directly, which is what this trait shells out to.

#[component]
fn app( count: String) -> Element {
    let id: i32 = count.parse().throw()?;

    rsx! {
        div { "Count {}" }
    }
}

Provided Methods§

source

fn throw_with<D>(self, e: impl FnOnce() -> D) -> Option<Self::Out>
where D: Debug + 'static,

Returns an option that evaluates to None if there is an error, injecting the error to the nearest error boundary.

If the value is Ok, then throw returns the value, not aborting the rendering process.

The call stack is saved for this component and provided to the error boundary

Note that you can also manually throw errors using the throw method on ScopeState directly, which is what this trait shells out to.

#[component]
fn app( count: String) -> Element {
    let id: i32 = count.parse().throw()?;

    rsx! {
        div { "Count {}" }
    }
}

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<'a, T, O, E> Throw for &'a Result<T, E>
where O: Debug + 'static, E: ToOwned<Owned = O>,

We call clone on any errors that can be owned out of a reference

§

type Out = &'a T

source§

fn throw(self) -> Option<<&'a Result<T, E> as Throw>::Out>

source§

fn throw_with<D>( self, err: impl FnOnce() -> D ) -> Option<<&'a Result<T, E> as Throw>::Out>
where D: Debug + 'static,

source§

impl<T> Throw for Option<T>

Or just throw errors we know about

§

type Out = T

source§

fn throw(self) -> Option<T>

source§

fn throw_with<D>( self, error: impl FnOnce() -> D ) -> Option<<Option<T> as Throw>::Out>
where D: Debug + 'static,

source§

impl<T, E> Throw for Result<T, E>
where E: Debug + 'static,

Or just throw errors we know about

§

type Out = T

source§

fn throw(self) -> Option<T>

source§

fn throw_with<D>( self, error: impl FnOnce() -> D ) -> Option<<Result<T, E> as Throw>::Out>
where D: Debug + 'static,

Implementors§