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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
pub use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
pub use rust_decimal::Decimal;

#[derive(Debug, PartialEq, Eq)]
pub enum Comment<'a> {
    UserComment(&'a str),
    Attribute(&'a str),
}

#[derive(Debug, PartialEq, Eq)]
pub struct Position<'a> {
    pub amount: Decimal,
    pub commodity: Option<&'a str>,
}

// XXX: Rename
#[derive(Debug, PartialEq, Eq)]
pub struct PostingDetail<'a> {
    pub main_position: Position<'a>,
    pub value_position: Option<Position<'a>>,
}

#[derive(Debug, PartialEq, Eq)]
pub struct Posting<'a> {
    pub account_name: AccountName<'a>,
    pub posting_detail: Option<PostingDetail<'a>>,
    pub comment: Option<Comment<'a>>,
}

#[derive(Debug, PartialEq, Eq)]
pub struct TransactionHeader<'a> {
    pub datetime: DateTime,
    pub status_mark: StatusMark,
    pub code: Option<&'a str>,
    pub description: &'a str,
}

#[derive(Debug, PartialEq, Eq)]
pub enum Timezone {
    Utc,
    FixedOffset(i16),
}

#[derive(Debug, PartialEq, Eq)]
pub enum DateTime {
    Date(NaiveDate),
    DateTime(NaiveDateTime),
    DateTimeTz(NaiveDateTime, Timezone),
}

#[derive(Debug, PartialEq, Eq)]
pub enum Line<'a> {
    Empty,
    TransactionHeader(TransactionHeader<'a>),
    TransactionComment(Comment<'a>),
    Posting(Posting<'a>),
}

#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub enum StatusMark {
    /// No mark
    Unmarked,
    /// `!`
    Pending,
    /// `*`
    Cleared,
}

#[derive(Debug, PartialEq, Eq)]
pub enum AccountName<'a> {
    /// A regular "balancing" account name
    Regular(&'a str),
    /// A virtual "non-balancing" account name
    Virtual(&'a str),
}