reactive_graph_reactive_service_api/property/property_u64/
operator.rs

1use crate::TypedReactivePropertyImpl;
2use reactive_graph_reactive_model_api::ReactiveInstance;
3use serde_json::json;
4use std::ops::Add;
5use std::ops::AddAssign;
6use std::ops::Div;
7use std::ops::DivAssign;
8use std::ops::Mul;
9use std::ops::MulAssign;
10use std::ops::Rem;
11use std::ops::RemAssign;
12use std::ops::Sub;
13use std::ops::SubAssign;
14
15impl<IdType, ReactiveInstanceType> AddAssign<u64> for TypedReactivePropertyImpl<IdType, ReactiveInstanceType, u64>
16where
17    IdType: Clone,
18    ReactiveInstanceType: ReactiveInstance<IdType>,
19{
20    fn add_assign(&mut self, rhs: u64) {
21        if let Some(v) = self.reactive_instance.as_u64(&self.property_name).map(|lhs| lhs.add(rhs)) {
22            self.reactive_instance.set(&self.property_name, json!(v));
23        }
24    }
25}
26
27impl<IdType, ReactiveInstanceType> SubAssign<u64> for TypedReactivePropertyImpl<IdType, ReactiveInstanceType, u64>
28where
29    IdType: Clone,
30    ReactiveInstanceType: ReactiveInstance<IdType>,
31{
32    fn sub_assign(&mut self, rhs: u64) {
33        if let Some(v) = self.reactive_instance.as_u64(&self.property_name).map(|lhs| lhs.sub(rhs)) {
34            self.reactive_instance.set(&self.property_name, json!(v));
35        }
36    }
37}
38
39impl<IdType, ReactiveInstanceType> MulAssign<u64> for TypedReactivePropertyImpl<IdType, ReactiveInstanceType, u64>
40where
41    IdType: Clone,
42    ReactiveInstanceType: ReactiveInstance<IdType>,
43{
44    fn mul_assign(&mut self, rhs: u64) {
45        if let Some(v) = self.reactive_instance.as_u64(&self.property_name).map(|lhs| lhs.mul(rhs)) {
46            self.reactive_instance.set(&self.property_name, json!(v));
47        }
48    }
49}
50
51impl<IdType, ReactiveInstanceType> DivAssign<u64> for TypedReactivePropertyImpl<IdType, ReactiveInstanceType, u64>
52where
53    IdType: Clone,
54    ReactiveInstanceType: ReactiveInstance<IdType>,
55{
56    fn div_assign(&mut self, rhs: u64) {
57        if rhs == 0 {
58            return;
59        }
60        if let Some(v) = self.reactive_instance.as_u64(&self.property_name).map(|lhs| lhs.div(rhs)) {
61            self.reactive_instance.set(&self.property_name, json!(v));
62        }
63    }
64}
65
66impl<IdType, ReactiveInstanceType> RemAssign<u64> for TypedReactivePropertyImpl<IdType, ReactiveInstanceType, u64>
67where
68    IdType: Clone,
69    ReactiveInstanceType: ReactiveInstance<IdType>,
70{
71    fn rem_assign(&mut self, rhs: u64) {
72        if rhs == 0 {
73            return;
74        }
75        if let Some(v) = self.reactive_instance.as_u64(&self.property_name).map(|lhs| lhs.rem(rhs)) {
76            self.reactive_instance.set(&self.property_name, json!(v));
77        }
78    }
79}