leptos_use/utils/
use_derive_signal.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/// Macro to easily create helper functions that derive a signal using a piece of code.
///
/// See [`fn@crate::is_ok`] or [`fn@crate::use_to_string`] as examples.
#[macro_export]
macro_rules! use_derive_signal {
    (
        $(#[$outer:meta])*
        $name:ident <$inner_signal_type:tt $(< $( $inner_type_param:tt ),+ >)? $(, $( $type_param:tt $( : $first_bound:tt $(+ $rest_bound:tt)* )? ),+ )? > -> $return_type:tt
        $($body:tt)+
    ) => {
        $(#[$outer])*
        pub fn $name<V $(, $( $type_param ),* )? >(value: V) -> Signal<$return_type>
        where
            V: Into<MaybeSignal<$inner_signal_type $(< $( $inner_type_param ),+ >)?>> $(, $( $type_param $( : $first_bound $(+ $rest_bound)* )? ),+ )?
        {
            let value = value.into();
            Signal::derive(move || value.with($($body)+))
        }
    };
}