added is_ok and is_err

This commit is contained in:
Maccesch 2023-07-16 14:04:42 +01:00
parent 67bdde2960
commit 880eca30da
8 changed files with 70 additions and 0 deletions

View file

@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### New Functions 🚀
- `is_err`
- `is_ok`
- `is_none`
- `is_some`
- `use_raf_fn`

View file

@ -63,7 +63,9 @@
# Utilities
- [is_err](utilities/is_err.md)
- [is_none](utilities/is_none.md)
- [is_ok](utilities/is_ok.md)
- [is_some](utilities/is_some.md)
- [use_cycle_list](utilities/use_cycle_list.md)
- [use_debounce_fn](utilities/use_debounce_fn.md)

View file

@ -0,0 +1,3 @@
# is_err
<!-- cmdrun python3 ../extract_doc_comment.py is_err -->

View file

@ -0,0 +1,3 @@
# is_ok
<!-- cmdrun python3 ../extract_doc_comment.py is_ok -->

View file

@ -2,7 +2,9 @@
resolver = "2"
members = [
"is_err",
"is_none",
"is_ok",
"is_some",
"on_click_outside",
"use_abs",

27
src/is_err.rs Normal file
View file

@ -0,0 +1,27 @@
use crate::utils::use_derive_signal;
use leptos::*;
use_derive_signal!(
/// Reactive `Result::is_err()`.
///
/// ## Usage
///
/// ```
/// # use leptos::*;
/// # use leptos_use::is_err;
/// #
/// # #[component]
/// # fn Demo(cx: Scope) -> impl IntoView {
/// let (example, set_example) = create_signal(
/// cx,
/// if js_sys::Math::random() < 0.5 { Ok("Example") } else { Err(()) }
/// );
///
/// let is_error = is_err(cx, example);
/// #
/// # view! { cx, }
/// # }
/// ```
is_err<Result<T, ()>, T: 'static> -> bool
|value| value.is_err()
);

27
src/is_ok.rs Normal file
View file

@ -0,0 +1,27 @@
use crate::utils::use_derive_signal;
use leptos::*;
use_derive_signal!(
/// Reactive `Result::is_ok()`.
///
/// ## Usage
///
/// ```
/// # use leptos::*;
/// # use leptos_use::is_ok;
/// #
/// # #[component]
/// # fn Demo(cx: Scope) -> impl IntoView {
/// let (example, set_example) = create_signal(
/// cx,
/// if js_sys::Math::random() < 0.5 { Ok("Example") } else { Err(()) }
/// );
///
/// let is_ok = is_ok(cx, example);
/// #
/// # view! { cx, }
/// # }
/// ```
is_ok<Result<T, ()>, T: 'static> -> bool
|value| value.is_ok()
);

View file

@ -21,6 +21,8 @@ cfg_if! { if #[cfg(web_sys_unstable_apis)] {
}}
mod on_click_outside;
mod is_err;
mod is_ok;
mod is_none;
mod is_some;
mod use_active_element;
@ -58,6 +60,8 @@ mod watch_throttled;
mod whenever;
pub use on_click_outside::*;
pub use is_err::*;
pub use is_ok::*;
pub use is_none::*;
pub use is_some::*;
pub use use_active_element::*;