2019-12-22 21:30:26 +00:00
|
|
|
pub mod parser_error {
|
|
|
|
use std::fmt;
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
|
|
pub struct Waehrung;
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
|
|
pub struct TransactionDirection;
|
|
|
|
|
|
|
|
impl std::error::Error for TransactionDirection {}
|
|
|
|
|
|
|
|
impl std::error::Error for Waehrung {}
|
|
|
|
|
|
|
|
impl fmt::Display for Waehrung {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
write!(f, "invalid currency")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for TransactionDirection {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
write!(f, "invalid H/S")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-23 16:35:06 +00:00
|
|
|
use {
|
|
|
|
serde::{Deserialize, Serialize},
|
|
|
|
std::fmt,
|
|
|
|
};
|
2019-12-22 21:30:26 +00:00
|
|
|
|
2019-12-23 16:35:06 +00:00
|
|
|
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
|
2019-12-22 21:30:26 +00:00
|
|
|
pub enum Waehrung {
|
|
|
|
EUR,
|
|
|
|
USD,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for Waehrung {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
write!(f, "{:?}", self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::str::FromStr for Waehrung {
|
|
|
|
type Err = parser_error::Waehrung;
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
Ok(match s {
|
|
|
|
"EUR" => Waehrung::EUR,
|
|
|
|
"USD" => Waehrung::USD,
|
|
|
|
_ => return Err(parser_error::Waehrung),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-23 16:35:06 +00:00
|
|
|
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
|
2019-12-22 21:30:26 +00:00
|
|
|
pub enum TransactionDirection {
|
|
|
|
Haben, // H = Gutschrift
|
|
|
|
Soll, // S = Belastung
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for TransactionDirection {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
write!(
|
|
|
|
f,
|
|
|
|
"{}",
|
|
|
|
match self {
|
|
|
|
TransactionDirection::Haben => "H",
|
|
|
|
TransactionDirection::Soll => "S",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::str::FromStr for TransactionDirection {
|
|
|
|
type Err = parser_error::TransactionDirection;
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
Ok(match s {
|
|
|
|
"H" => TransactionDirection::Haben,
|
|
|
|
"S" => TransactionDirection::Soll,
|
|
|
|
_ => return Err(parser_error::TransactionDirection),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|