leptos-use/src/is_err.rs

26 lines
576 B
Rust
Raw Normal View History

2023-07-16 14:04:42 +01:00
use leptos::*;
2024-07-08 16:09:24 +02:00
crate::use_derive_signal!(
2023-07-16 14:04:42 +01:00
/// Reactive `Result::is_err()`.
///
/// ## Usage
///
/// ```
/// # use leptos::*;
/// # use leptos_use::is_err;
/// #
/// # #[component]
2023-07-27 18:06:36 +01:00
/// # fn Demo() -> impl IntoView {
2023-07-16 14:04:42 +01:00
/// let (example, set_example) = create_signal(
/// if js_sys::Math::random() < 0.5 { Ok("Example") } else { Err(()) }
/// );
///
2023-07-27 18:06:36 +01:00
/// let is_error = is_err(example);
2023-07-16 14:04:42 +01:00
/// #
2023-07-27 18:06:36 +01:00
/// # view! { }
2023-07-16 14:04:42 +01:00
/// # }
/// ```
is_err<Result<T, ()>, T: 'static> -> bool
|value| value.is_err()
);