reactive_graph_reactive_service_api/property/property_bool/
callable.rs1use crate::TypedReactivePropertyImpl;
2use reactive_graph_reactive_model_api::ReactiveInstance;
3use serde_json::json;
4
5#[rustversion::nightly]
6impl<IdType, ReactiveInstanceType> FnOnce<(bool,)> for TypedReactivePropertyImpl<IdType, ReactiveInstanceType, bool>
7where
8 IdType: Clone,
9 ReactiveInstanceType: ReactiveInstance<IdType>,
10{
11 type Output = ();
12
13 extern "rust-call" fn call_once(mut self, args: (bool,)) -> Self::Output {
14 self.call_mut(args)
15 }
16}
17
18#[rustversion::nightly]
19impl<IdType, ReactiveInstanceType> FnMut<(bool,)> for TypedReactivePropertyImpl<IdType, ReactiveInstanceType, bool>
20where
21 IdType: Clone,
22 ReactiveInstanceType: ReactiveInstance<IdType>,
23{
24 extern "rust-call" fn call_mut(&mut self, args: (bool,)) -> Self::Output {
25 self.call(args)
26 }
27}
28
29#[rustversion::nightly]
30impl<IdType, ReactiveInstanceType> Fn<(bool,)> for TypedReactivePropertyImpl<IdType, ReactiveInstanceType, bool>
31where
32 IdType: Clone,
33 ReactiveInstanceType: ReactiveInstance<IdType>,
34{
35 extern "rust-call" fn call(&self, args: (bool,)) -> Self::Output {
36 self.reactive_instance.set(&self.property_name, json!(args.0));
37 }
38}
39
40impl<IdType, ReactiveInstanceType> TypedReactivePropertyImpl<IdType, ReactiveInstanceType, bool>
41where
42 IdType: Clone,
43 ReactiveInstanceType: ReactiveInstance<IdType>,
44{
45 pub fn op<F>(&self, f: F)
46 where
47 F: Fn(bool) -> bool,
48 {
49 if let Some(v) = self.reactive_instance.as_bool(&self.property_name) {
50 self.reactive_instance.set(&self.property_name, json!(f(v)));
51 }
52 }
53}