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§
type Out
type Out
The value that will be returned in if the given value is Ok
.
Required Methods§
fn throw(self) -> Option<Self::Out>
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§
fn throw_with<D>(self, e: impl FnOnce() -> D) -> Option<Self::Out>where
D: Debug + 'static,
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§
Implementations on Foreign Types§
§impl<'a, T, O, E> Throw for &'a Result<T, E>where
O: Debug + 'static,
E: ToOwned<Owned = O>,
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