reactive_graph_reactive_service_api/property/property_i64/
callable.rs

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