leptos-use/src/is_ok.rs

27 lines
598 B
Rust
Raw Normal View History

2023-07-16 14:04:42 +01:00
use crate::utils::use_derive_signal;
use leptos::*;
use_derive_signal!(
/// Reactive `Result::is_ok()`.
///
/// ## Usage
///
/// ```
/// # use leptos::*;
/// # use leptos_use::is_ok;
/// #
/// # #[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_ok = is_ok(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_ok<Result<T, ()>, T: 'static> -> bool
|value| value.is_ok()
);