spec.rs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. use std::collections::HashMap;
  2. use super::{AccountName, UnitName};
  3. #[derive(Debug, serde::Deserialize, PartialEq)]
  4. #[serde(deny_unknown_fields, rename_all = "snake_case")]
  5. pub enum CsvColumnSpec {
  6. Ignore,
  7. Datestamp,
  8. Title,
  9. Deposit,
  10. Withdraw,
  11. Change,
  12. Balance,
  13. Unit,
  14. }
  15. #[derive(Debug, serde::Deserialize)]
  16. #[serde(deny_unknown_fields)]
  17. pub struct CsvImportSpec {
  18. pub skip_start: Option<usize>,
  19. pub skip_end: Option<usize>,
  20. pub cols: Vec<CsvColumnSpec>,
  21. pub date_format: String,
  22. }
  23. #[derive(Debug, serde::Deserialize)]
  24. #[serde(deny_unknown_fields, tag = "format", rename_all = "snake_case")]
  25. pub enum ImportFileFormat {
  26. Csv(CsvImportSpec),
  27. }
  28. #[derive(Debug, serde::Deserialize)]
  29. #[serde(deny_unknown_fields)]
  30. pub struct AccountSpec {
  31. pub title: Option<String>,
  32. pub description: Option<String>,
  33. pub annotations: Option<HashMap<String, String>>,
  34. pub unit: Option<UnitName>,
  35. pub import: Option<ImportFileFormat>,
  36. }
  37. #[derive(Debug, serde::Deserialize)]
  38. #[serde(deny_unknown_fields)]
  39. pub struct UnitSpec {
  40. pub name: UnitName,
  41. pub precision: Option<u32>,
  42. }
  43. #[derive(Debug, serde::Deserialize)]
  44. #[serde(deny_unknown_fields)]
  45. pub struct SpecRoot {
  46. pub ledger_path: std::path::PathBuf,
  47. pub units: HashMap<UnitName, UnitSpec>,
  48. pub placeholder_account: AccountName,
  49. pub accounts: HashMap<AccountName, AccountSpec>,
  50. }