processor/src/core.rs
Bruno BELANYI ffd6a20a30 transaction: add CSV deserialization
It is unfortunate that both [1] and [2] conspire to make this code way
worse than it could otherwise be with a saner (de)serialization format.

We both need to introduce `TransactionRecord` due to tagged enums not
being powerful enough in CSV, and make its `amount` field optional to
deal with the varying number of fields for each kind of transaction.

[1]: https://github.com/BurntSushi/rust-csv/issues/211
[2]: https://github.com/BurntSushi/rust-csv/issues/172
2022-08-23 14:05:03 +02:00

28 lines
1 KiB
Rust

//! Core types used in the processing of payments.
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, DisplayFromStr};
/// Clients are anonymous, identified by globally unique ids. "16-bit ought to be enough for
/// anyone".
#[derive(
Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize,
)]
#[serde(transparent)]
pub struct ClientId(pub u16);
/// Transactions are identified by a globally unique id. 32 bit is sufficient for our puposes.
#[derive(
Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize,
)]
#[serde(transparent)]
pub struct TxId(pub u32);
/// Amounts are represented as exact decimals, up to four places past the decimal.
/// For ease of implementation, make use of [fpdec::Decimal] instead of implementing a custom
/// fixed-point number.
#[serde_as]
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize)]
#[serde(transparent)]
pub struct TxAmount(#[serde_as(as = "DisplayFromStr")] pub fpdec::Decimal);