mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 06:44:17 +00:00
Add beginner tip to ErrorBoundary (#2385)
* Add beginner tip to ErrorBoundary This might seem simple, but the nuances of types and traits confuse many people learning the language. * edit * Update error_boundary.rs * edits * ignore error block
This commit is contained in:
parent
1ff0a7176d
commit
35a8ca1f39
1 changed files with 22 additions and 0 deletions
|
@ -48,6 +48,28 @@ use leptos_reactive::{provide_context, run_as_child, signal_prelude::*};
|
||||||
/// {move || {
|
/// {move || {
|
||||||
/// /* etc. */
|
/// /* etc. */
|
||||||
/// ```
|
/// ```
|
||||||
|
///
|
||||||
|
/// ## Beginner's Tip: ErrorBoundary Requires Your Error To Implement std::error::Error.
|
||||||
|
/// `ErrorBoundary` requires your `Result<T,E>` to implement [IntoView](https://docs.rs/leptos/latest/leptos/trait.IntoView.html).
|
||||||
|
/// `Result<T,E>` only implements `IntoView` if `E` implements [std::error::Error](https://doc.rust-lang.org/std/error/trait.Error.html).
|
||||||
|
/// So, for instance, if you pass a `Result<T,String>` where `T` implements [IntoView](https://docs.rs/leptos/latest/leptos/trait.IntoView.html)
|
||||||
|
/// and attempt to render the error for the purposes of `ErrorBoundary` you'll get a compiler error like this.
|
||||||
|
///
|
||||||
|
/// ```rust,ignore
|
||||||
|
/// error[E0599]: the method `into_view` exists for enum `Result<ViewableLoginFlow, String>`, but its trait bounds were not satisfied
|
||||||
|
/// --> src/login.rs:229:32
|
||||||
|
/// |
|
||||||
|
/// 229 | err => err.into_view(),
|
||||||
|
/// | ^^^^^^^^^ method cannot be called on `Result<ViewableLoginFlow, String>` due to unsatisfied trait bounds
|
||||||
|
/// |
|
||||||
|
/// = note: the following trait bounds were not satisfied:
|
||||||
|
/// `<&Result<ViewableLoginFlow, std::string::String> as FnOnce<()>>::Output = _`
|
||||||
|
/// which is required by `&Result<ViewableLoginFlow, std::string::String>: leptos::IntoView`
|
||||||
|
/// ... more notes here ...
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// For more information about how to easily implement `Error` see
|
||||||
|
/// [thiserror](https://docs.rs/thiserror/latest/thiserror/)
|
||||||
#[component]
|
#[component]
|
||||||
pub fn ErrorBoundary<F, IV>(
|
pub fn ErrorBoundary<F, IV>(
|
||||||
/// The components inside the tag which will get rendered
|
/// The components inside the tag which will get rendered
|
||||||
|
|
Loading…
Reference in a new issue