1#![no_std]
4#![forbid(unsafe_code)]
5extern crate alloc;
6
7use crate::watcher::{Context, WatcherGuard};
8
9pub mod collection;
11pub mod watcher;
12
13pub trait Signal: Clone + 'static {
18 type Output: 'static;
20 type Guard: WatcherGuard;
22
23 fn get(&self) -> Self::Output;
25
26 #[must_use]
30 fn watch(&self, watcher: impl Fn(Context<Self::Output>) + 'static) -> Self::Guard;
31}
32
33pub trait CustomBinding: Signal {
38 fn set(&mut self, value: Self::Output);
42}
43
44#[macro_export]
49macro_rules! impl_constant {
50 ($($ty:ty),*) => {
51 $(
52 impl $crate::Signal for $ty {
53 type Output = Self;
54 type Guard = ();
55
56 fn get(&self) -> Self::Output {
57 self.clone()
58 }
59
60 fn watch(
61 &self,
62 _watcher: impl Fn($crate::watcher::Context<Self::Output>)+'static,
63 ) {
64
65 }
66 }
67 )*
68 };
69
70}
71
72macro_rules! impl_generic_constant {
73
74 ( $($ty:ident < $($param:ident),* >),* $(,)? ) => {
75 $(
76 impl<$($param: Clone + 'static),*> $crate::Signal for $ty<$($param),*> {
77 type Output = Self;
78 type Guard = ();
79
80 fn get(&self) -> Self::Output {
81 self.clone()
82 }
83
84 fn watch(
85 &self,
86 _watcher: impl Fn($crate::watcher::Context<Self::Output>)+'static,
87 ) {
88
89 }
90 }
91 )*
92 };
93
94
95
96
97}
98
99mod impl_constant {
100 use alloc::borrow::Cow;
101 use alloc::collections::BTreeMap;
102 use core::time::Duration;
103
104 use crate::Signal;
105 use alloc::string::String;
106 use alloc::vec::Vec;
107 impl_constant!(
108 &'static str,
109 u8,
110 u16,
111 u32,
112 u64,
113 i8,
114 i16,
115 i32,
116 i64,
117 f32,
118 f64,
119 bool,
120 char,
121 Duration,
122 String,
123 Cow<'static, str>
124 );
125
126 impl_generic_constant!(Vec<T>,BTreeMap<K,V>,Option<T>,Result<T,E>);
127
128 impl<T: 'static> Signal for &'static [T] {
129 type Output = &'static [T];
130 type Guard = ();
131 fn get(&self) -> Self::Output {
132 self
133 }
134 fn watch(&self, _watcher: impl Fn(crate::watcher::Context<Self::Output>) + 'static) {}
135 }
136}