pub struct ErrorBoundary { /* private fields */ }Expand description
A handle that tracks whether a wrapped subtree has thrown.
The boundary’s phase is exposed via phase() as a
Signal<ErrorBoundaryPhase>. The parent component
reads that signal to decide whether to render the
child or a fallback.
try_with(closure) runs the closure and, if it
panics, transitions the boundary to Caught. The
closure’s return value (if it didn’t panic) is
returned to the caller; if it panicked, an Err
is returned containing the panic message.
Implementations§
Source§impl ErrorBoundary
Inherent implementation of ErrorBoundary.
impl ErrorBoundary
Inherent implementation of ErrorBoundary.
Sourcepub fn try_with<F, R>(&self, closure: F) -> Result<R, String>where
F: FnOnce() -> R + UnwindSafe,
pub fn try_with<F, R>(&self, closure: F) -> Result<R, String>where
F: FnOnce() -> R + UnwindSafe,
Runs a closure and, if it panics, transitions
the boundary to Caught and returns Err.
On success, the closure’s return value is
returned wrapped in Ok. The closure is
wrapped in AssertUnwindSafe so it does not
have to satisfy UnwindSafe.
§Arguments
F: FnOnce() -> R + UnwindSafe- A generic type parameter.
§Returns
Result<R, String>- Result of the operation; anErrvariant on failure.
Sourcepub fn report_error(&self, message: &str) -> String
pub fn report_error(&self, message: &str) -> String
Feeds an Err straight into the boundary
without forcing the caller to panic!.
try_with requires a real panic to transition
the phase to Caught, which makes demonstrating
the hook from outside tests/ awkward. This
helper lets demo / driver code report a failure
message via the regular Result channel and
still flip the boundary into Caught.
§Arguments
&str- The error message to surface.
§Returns
String- The same message that was passed in.
Source§impl ErrorBoundary
impl ErrorBoundary
pub fn get_phase(&self) -> &Signal<ErrorBoundaryPhase>
pub fn get_mut_phase(&mut self) -> &mut Signal<ErrorBoundaryPhase>
pub fn set_phase(&mut self, val: Signal<ErrorBoundaryPhase>) -> &mut Self
Trait Implementations§
Source§impl Clone for ErrorBoundary
impl Clone for ErrorBoundary
Source§fn clone(&self) -> ErrorBoundary
fn clone(&self) -> ErrorBoundary
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for ErrorBoundary
ErrorBoundary is Copy because Signal<ErrorBoundaryPhase>
is itself Copy — the signal registry hands out cheap
usize addresses.
Source§impl Debug for ErrorBoundary
impl Debug for ErrorBoundary
Source§impl Default for ErrorBoundary
Default-construction for ErrorBoundary.
impl Default for ErrorBoundary
Default-construction for ErrorBoundary.
Source§fn default() -> Self
fn default() -> Self
Constructs a default ErrorBoundary value.
Source§impl Display for ErrorBoundary
Formatting / debug-printing for ErrorBoundary.
impl Display for ErrorBoundary
Formatting / debug-printing for ErrorBoundary.