Module monero::util::amount::serde

source ·
Available on crate feature serde only.
Expand description

This module adds serde serialization and deserialization support for Amounts. Since there is not a default way to serialize and deserialize Amounts, multiple ways are supported and it’s up to the user to decide which serialiation to use. The provided modules can be used as follows:

use serde_crate::{Serialize, Deserialize};
use monero::Amount;

#[derive(Serialize, Deserialize)]
pub struct HasAmount {
    #[serde(with = "monero::util::amount::serde::as_xmr")]
    pub amount: Amount,
}

Notabene that due to the limits of floating point precission, ::as_xmr serializes amounts as strings.

Modules

Serialize and deserialize Amount as real numbers denominated in piconero. Use with #[serde(with = "amount::serde::as_pico")].
Serialize and deserialize Amount as a string denominated in xmr. Use with #[serde(with = "amount::serde::as_xmr")].

Traits

This trait is used only to avoid code duplication and naming collisions of the different serde serialization crates.
This trait is only for internal Amount type serialization/deserialization.
This trait is for serialization of &[Amount] and &[SignedAmount] slices