1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use crate::;
/// Shows a fallback in place of child content that fails to render.
///
/// If any child content fails, the fallback closure receives the error.
/// Its view replaces all of the boundary's content, including content
/// already streamed to the browser. The rest of the page is unchanged.
///
/// Returning `Err` from the closure propagates the error to the enclosing
/// handler. The handler can change the response status only before the
/// response starts streaming.
///
/// ```rust
/// use topcoat::{
/// Result,
/// view::{View, component, error_boundary, view},
/// };
///
/// #[component]
/// async fn stats() -> Result<impl View> {
/// let visits = fetch_visits().await?;
/// Ok(view! { <p>(visits) " visits"</p> })
/// }
/// # async fn fetch_visits() -> Result<u32> { Ok(3) }
///
/// #[component]
/// async fn dashboard() -> Result<impl View> {
/// Ok(view! {
/// error_boundary(
/// fallback: |error| Ok(view! {
/// <p>"The stats are unavailable: " (error.to_string())</p>
/// }),
/// stats()
/// )
/// })
/// }
/// ```
///
/// Use [`live!`] and [`emit!`] directly for cases the component does not
/// cover, like retrying the child after an error.
///
/// [`live!`]: macro@crate::view::live
/// [`emit!`]: macro@crate::view::emit
pub async