2024-07-08 17:16:54 +01:00
|
|
|
/// Macro to easily create helper functions that derive a signal using a piece of code.
|
2024-07-27 18:23:28 +02:00
|
|
|
///
|
2024-07-27 18:10:38 +02:00
|
|
|
/// See [`fn@crate::is_ok`] or [`fn@crate::use_to_string`] as examples.
|
2024-07-08 16:09:24 +02:00
|
|
|
#[macro_export]
|
2023-07-16 14:00:12 +01:00
|
|
|
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])*
|
2023-07-27 18:06:36 +01:00
|
|
|
pub fn $name<V $(, $( $type_param ),* )? >(value: V) -> Signal<$return_type>
|
2023-07-16 14:00:12 +01:00
|
|
|
where
|
|
|
|
V: Into<MaybeSignal<$inner_signal_type $(< $( $inner_type_param ),+ >)?>> $(, $( $type_param $( : $first_bound $(+ $rest_bound)* )? ),+ )?
|
|
|
|
{
|
|
|
|
let value = value.into();
|
2023-07-27 18:06:36 +01:00
|
|
|
Signal::derive(move || value.with($($body)+))
|
2023-07-16 14:00:12 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|