dioxus_core/
render_error.rs

1use std::fmt::{Debug, Display};
2
3use crate::innerlude::*;
4
5/// An error that can occur while rendering a component
6#[derive(Clone, PartialEq, Debug)]
7pub enum RenderError {
8    /// The render function returned early
9    Aborted(CapturedError),
10
11    /// The component was suspended
12    Suspended(SuspendedFuture),
13}
14
15impl Default for RenderError {
16    fn default() -> Self {
17        struct RenderAbortedEarly;
18        impl Debug for RenderAbortedEarly {
19            fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20                f.write_str("Render aborted early")
21            }
22        }
23        impl Display for RenderAbortedEarly {
24            fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25                f.write_str("Render aborted early")
26            }
27        }
28        impl std::error::Error for RenderAbortedEarly {}
29        Self::Aborted(RenderAbortedEarly.into())
30    }
31}
32
33impl Display for RenderError {
34    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35        match self {
36            Self::Aborted(e) => write!(f, "Render aborted: {e}"),
37            Self::Suspended(e) => write!(f, "Component suspended: {e:?}"),
38        }
39    }
40}
41
42impl<E: std::error::Error + 'static> From<E> for RenderError {
43    fn from(e: E) -> Self {
44        Self::Aborted(CapturedError::from(e))
45    }
46}
47
48impl From<CapturedError> for RenderError {
49    fn from(e: CapturedError) -> Self {
50        RenderError::Aborted(e)
51    }
52}