MoneyV1 (src/money.rs)

lean-ctx · rust/crates/lean-ctx-protocol/src/money.rs · rust · Apache-2.0
payments, tag:knn-classified

Represents money with currency, coefficient, and scale.

// Source: https://github.com/yvgude/lean-ctx | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
use serde::{Deserialize, Serialize};

/// ISO 4217 currency code.
pub type CurrencyCode = String;

/// Sub-cent precision money. NOT floating point.
/// Rounding to legal minor units happens only at invoice time.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct MoneyV1 {
    pub currency: CurrencyCode,
    pub coefficient: i128,
    pub scale: u8,
}

#[cfg(test)]
mod tests {
    use crate::MoneyV1;

    #[test]
    fn serialization_round_trip() {
        let money = MoneyV1 {
            currency: "USD".to_owned(),
            coefficient: 12345,
            scale

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key