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

    // Required methods
    fn throw(self, cx: &ScopeState) -> Option<Self::Out>;
    fn throw_with<D: Debug + 'static>(
        self,
        cx: &ScopeState,
        e: impl FnOnce() -> D
    ) -> Option<Self::Out>;
}
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(cx: Scope, count: String) -> Element {
    let id: i32 = count.parse().throw(cx)?;

    cx.render(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, cx: &ScopeState) -> 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(cx: Scope, count: String) -> Element {
    let id: i32 = count.parse().throw(cx)?;

    cx.render(rsx! {
        div { "Count {}" }
    })
}
source

fn throw_with<D: Debug + 'static>( self, cx: &ScopeState, e: impl FnOnce() -> D ) -> 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(cx: Scope, count: String) -> Element {
    let id: i32 = count.parse().throw(cx)?;

    cx.render(rsx! {
        div { "Count {}" }
    })
}

Implementations on Foreign Types§

source§

impl<T> Throw<()> for Option<T>

Or just throw errors we know about

§

type Out = T

source§

fn throw(self, cx: &ScopeState) -> Option<T>

source§

fn throw_with<D: Debug + 'static>( self, cx: &ScopeState, error: impl FnOnce() -> D ) -> Option<Self::Out>

source§

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

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

§

type Out = &'a T

source§

fn throw(self, cx: &ScopeState) -> Option<Self::Out>

source§

fn throw_with<D: Debug + 'static>( self, cx: &ScopeState, err: impl FnOnce() -> D ) -> Option<Self::Out>

source§

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

Or just throw errors we know about

§

type Out = T

source§

fn throw(self, cx: &ScopeState) -> Option<T>

source§

fn throw_with<D: Debug + 'static>( self, cx: &ScopeState, error: impl FnOnce() -> D ) -> Option<Self::Out>

Implementors§