1#[allow(deprecated)]
2use crate::wrappers::read::{MaybeProp, MaybeSignal};
3use crate::{
4 computed::{ArcMemo, Memo},
5 owner::Storage,
6 signal::{
7 ArcReadSignal, ArcRwSignal, ArcWriteSignal, ReadSignal, RwSignal,
8 WriteSignal,
9 },
10 traits::{Get, Set},
11 wrappers::{
12 read::{ArcSignal, Signal, SignalTypes},
13 write::SignalSetter,
14 },
15};
16
17macro_rules! impl_set_fn_traits {
18 ($($ty:ident),*) => {
19 $(
20 #[cfg(all(feature = "nightly", rustc_nightly))]
21 impl<T> FnOnce<(T,)> for $ty<T> where $ty<T>: Set<Value = T> {
22 type Output = ();
23
24 #[inline(always)]
25 extern "rust-call" fn call_once(self, args: (T,)) -> Self::Output {
26 self.set(args.0);
27 }
28 }
29
30 #[cfg(all(feature = "nightly", rustc_nightly))]
31 impl<T> FnMut<(T,)> for $ty<T> where $ty<T>: Set<Value = T> {
32 #[inline(always)]
33 extern "rust-call" fn call_mut(&mut self, args: (T,)) -> Self::Output {
34 self.set(args.0);
35 }
36 }
37
38 #[cfg(all(feature = "nightly", rustc_nightly))]
39 impl<T> Fn<(T,)> for $ty<T> where $ty<T>: Set<Value = T> {
40 #[inline(always)]
41 extern "rust-call" fn call(&self, args: (T,)) -> Self::Output {
42 self.set(args.0);
43 }
44 }
45 )*
46 };
47}
48
49macro_rules! impl_set_fn_traits_arena {
50 ($($ty:ident),*) => {
51 $(
52 #[cfg(all(feature = "nightly", rustc_nightly))]
53 impl<T, S> FnOnce<(T,)> for $ty<T, S> where $ty<T, S>: Set<Value = T> {
54 type Output = ();
55
56 #[inline(always)]
57 extern "rust-call" fn call_once(self, args: (T,)) -> Self::Output {
58 self.set(args.0);
59 }
60 }
61
62 #[cfg(all(feature = "nightly", rustc_nightly))]
63 impl<T, S> FnMut<(T,)> for $ty<T, S> where $ty<T, S>: Set<Value = T> {
64 #[inline(always)]
65 extern "rust-call" fn call_mut(&mut self, args: (T,)) -> Self::Output {
66 self.set(args.0);
67 }
68 }
69
70 #[cfg(all(feature = "nightly", rustc_nightly))]
71 impl<T, S> Fn<(T,)> for $ty<T, S> where $ty<T, S>: Set<Value = T> {
72 #[inline(always)]
73 extern "rust-call" fn call(&self, args: (T,)) -> Self::Output {
74 self.set(args.0);
75 }
76 }
77 )*
78 };
79}
80
81macro_rules! impl_get_fn_traits_get {
82 ($($ty:ident),*) => {
83 $(
84 #[cfg(all(feature = "nightly", rustc_nightly))]
85 impl<T> FnOnce<()> for $ty<T> where $ty<T>: Get {
86 type Output = <Self as Get>::Value;
87
88 #[inline(always)]
89 extern "rust-call" fn call_once(self, _args: ()) -> Self::Output {
90 self.get()
91 }
92 }
93
94 #[cfg(all(feature = "nightly", rustc_nightly))]
95 impl<T> FnMut<()> for $ty<T> where $ty<T>: Get {
96 #[inline(always)]
97 extern "rust-call" fn call_mut(&mut self, _args: ()) -> Self::Output {
98 self.get()
99 }
100 }
101
102 #[cfg(all(feature = "nightly", rustc_nightly))]
103 impl<T> Fn<()> for $ty<T> where $ty<T>: Get {
104 #[inline(always)]
105 extern "rust-call" fn call(&self, _args: ()) -> Self::Output {
106 self.get()
107 }
108 }
109 )*
110 };
111}
112
113macro_rules! impl_get_fn_traits_get_arena {
114 ($($ty:ident),*) => {
115 $(
116 #[cfg(all(feature = "nightly", rustc_nightly))]
117 #[allow(deprecated)]
118 impl<T, S> FnOnce<()> for $ty<T, S> where $ty<T, S>: Get, S: Storage<T> + Storage<Option<T>> + Storage<SignalTypes<Option<T>, S>> {
119 type Output = <Self as Get>::Value;
120
121 #[inline(always)]
122 extern "rust-call" fn call_once(self, _args: ()) -> Self::Output {
123 self.get()
124 }
125 }
126
127 #[cfg(all(feature = "nightly", rustc_nightly))]
128 #[allow(deprecated)]
129 impl<T, S> FnMut<()> for $ty<T, S> where $ty<T, S>: Get, S: Storage<T> + Storage<Option<T>> + Storage<SignalTypes<Option<T>, S>> {
130 #[inline(always)]
131 extern "rust-call" fn call_mut(&mut self, _args: ()) -> Self::Output {
132 self.get()
133 }
134 }
135
136 #[cfg(all(feature = "nightly", rustc_nightly))]
137 #[allow(deprecated)]
138 impl<T, S> Fn<()> for $ty<T, S> where $ty<T, S>: Get, S: Storage<T> + Storage<Option<T>> + Storage<SignalTypes<Option<T>, S>> {
139 #[inline(always)]
140 extern "rust-call" fn call(&self, _args: ()) -> Self::Output {
141 self.get()
142 }
143 }
144 )*
145 };
146}
147
148impl_get_fn_traits_get![ArcReadSignal, ArcRwSignal];
149impl_get_fn_traits_get_arena![
150 ReadSignal,
151 RwSignal,
152 ArcMemo,
153 ArcSignal,
154 Signal,
155 MaybeSignal,
156 Memo,
157 MaybeProp
158];
159impl_set_fn_traits![ArcRwSignal, ArcWriteSignal];
160impl_set_fn_traits_arena![RwSignal, WriteSignal, SignalSetter];