Trait freya::prelude::Throw

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

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

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

Required Associated Types§

type Out

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

Required Methods§

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 {}" }
    })
}

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

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

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

§

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

§

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

§

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

§

impl<T> Throw for Option<T>

Or just throw errors we know about

§

type Out = T

§

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

§

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

§

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

Or just throw errors we know about

§

type Out = T

§

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

§

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

Implementors§