use {
::serde::{Deserialize, Serialize},
};
#[derive(Serialize, Deserialize, Debug)]
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
}
}