1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use {
::serde::{Deserialize, Serialize},
};
#[derive(Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct DittoCounterStoredFormat {
_value: f64,
#[serde(rename = "_ditto_internal_type_jkb12973t4b")]
_type: u64,
}
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
#[serde(from = "f64")]
#[serde(into = "DittoCounterStoredFormat")]
pub struct DittoCounter {
pub(crate) value: f64,
}
impl From<f64> for DittoCounter {
fn from(value : f64) -> DittoCounter {
DittoCounter{value}
}
}
impl From<DittoCounter> for DittoCounterStoredFormat {
fn from(
DittoCounter { value }: DittoCounter,
) -> DittoCounterStoredFormat {
Self {
_value: value,
_type: ::ffi_sdk::DittoCrdtType::Counter as u64,
}
}
}
impl Default for DittoCounter {
fn default() -> Self {
Self::new()
}
}
impl DittoCounter {
pub fn new() -> Self {
Self { value:0. }
}
pub(super) fn new_with_value(value:f64) -> Self {
Self { value }
}
pub fn value(&self) -> f64 {
self.value
}
}