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
|
use chrono::NaiveDate;
use serde::{Deserialize, Serialize};
use std::string::ToString;
/// A specification to build invoice IDs with
#[derive(Serialize, Deserialize)]
pub enum InvoiceId {
YearMonthId(u16, u8, usize),
}
impl ToString for InvoiceId {
fn to_string(&self) -> String {
match self {
Self::YearMonthId(yr, mo, id) => format!("#{}-{:02}-{:04}", yr, mo, id),
}
}
}
/// An invoice for a specific project
#[derive(Serialize, Deserialize)]
pub struct Invoice {
id: InvoiceId,
client: String,
project: String,
date: NaiveDate,
amount: usize,
currency: String,
vat: u8,
}
#[test]
fn invoice_id_fmt() {
let inv_id = InvoiceId::YearMonthId(2020, 06, 0055);
assert_eq!(inv_id.to_string(), "#2020-06-0055".to_string());
}
|