Skip to main content

rust_ynab/ynab/
common.rs

1use serde::{Deserialize, Serialize};
2
3/// An opaque, monotonically increasing sync cursor returned alongside most list/write
4/// responses. Store it and pass it back into `.with_server_knowledge()` on a later call to
5/// receive only the changes since that point (a delta request).
6#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)]
7pub struct ServerKnowledge(pub i64);
8
9impl std::fmt::Display for ServerKnowledge {
10    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
11        write!(f, "{}", self.0)
12    }
13}
14
15impl From<i64> for ServerKnowledge {
16    fn from(value: i64) -> Self {
17        Self(value)
18    }
19}
20
21impl From<ServerKnowledge> for i64 {
22    fn from(value: ServerKnowledge) -> Self {
23        value.0
24    }
25}
26
27impl PartialEq<i64> for ServerKnowledge {
28    fn eq(&self, other: &i64) -> bool {
29        self.0 == *other
30    }
31}
32
33impl PartialEq<ServerKnowledge> for i64 {
34    fn eq(&self, other: &ServerKnowledge) -> bool {
35        *self == other.0
36    }
37}
38
39impl PartialOrd<i64> for ServerKnowledge {
40    fn partial_cmp(&self, other: &i64) -> Option<std::cmp::Ordering> {
41        self.0.partial_cmp(other)
42    }
43}
44
45impl PartialOrd<ServerKnowledge> for i64 {
46    fn partial_cmp(&self, other: &ServerKnowledge) -> Option<std::cmp::Ordering> {
47        self.partial_cmp(&other.0)
48    }
49}
50
51#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
52pub struct DateFormat {
53    pub format: String,
54}
55
56#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
57pub struct CurrencyFormat {
58    pub iso_code: String,
59    pub example_format: String,
60    pub decimal_digits: usize,
61    pub decimal_separator: String,
62    pub symbol_first: bool,
63    pub group_separator: String,
64    pub currency_symbol: String,
65    pub display_symbol: bool,
66}
67
68pub(crate) const NO_PARAMS: Option<&[(&str, &str)]> = None;