leptos_use/utils/
use_derive_signal.rs

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