1#[macro_export]
2macro_rules! get_state {
3 ($type:ty) => {{
4 use rustato::{once_cell, State, GLOBAL_STATE_MANAGER};
5
6 static STATE: once_cell::sync::Lazy<State<$type>> = once_cell::sync::Lazy::new(|| {
7 rustato::GLOBAL_STATE_MANAGER
8 .get_state::<$type>(stringify!($type))
9 .unwrap_or_else(|| panic!("Estado '{}' não encontrado. Certifique-se de que create_state!() foi chamado para este tipo.", stringify!($type)))
10 });
11 &*STATE
12 }};
13}
14
15#[macro_export]
16macro_rules! on_state_change {
17 ($type:ty, $callback:expr) => {{
18 use rustato::{GLOBAL_STATE_MANAGER, StateChangeCallback};
19 let callback: StateChangeCallback<$type> = Box::new($callback);
20 rustato::GLOBAL_STATE_MANAGER.register_callback::<$type>(stringify!($type), callback);
21 }};
22}