paystack/models/
currency.rs

1//! Currency
2//! ===============
3//! This file contains the currency options for the paystack API.
4
5use serde::{Deserialize, Serialize};
6use std::fmt;
7
8/// Represents different currencies supported by the Paystack API.
9///
10/// The `Currency` enum defines the possible currency options that can be used with Paystack,
11/// including Nigerian Naira (NGN), Ghanaian Cedis (GHS), American Dollar (USD),
12/// and South African Rands (ZAR). It also includes an `EMPTY` variant to represent cases
13/// where the currency can be empty.
14///
15/// # Variants
16///
17/// - `NGN`: Nigerian Naira.
18/// - `GHS`: Ghanaian Cedis.
19/// - `USD`: American Dollar.
20/// - `ZAR`: South African Rands.
21/// - `EMPTY`: Used when the currency can be empty.
22///
23/// # Examples
24///
25/// ```
26/// use paystack::Currency;
27///
28/// let ngn = Currency::NGN;
29/// let ghs = Currency::GHS;
30/// let usd = Currency::USD;
31/// let zar = Currency::ZAR;
32/// let empty = Currency::EMPTY;
33///
34/// println!("{:?}", ngn); // Prints: NGN
35/// ```
36///
37/// The example demonstrates the usage of the `Currency` enum from the Paystack crate,
38/// creating instances of each variant and printing a debug representation.
39#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq)]
40pub enum Currency {
41    /// Nigerian Naira
42    #[default]
43    NGN,
44    /// Ghanaian Cedis
45    GHS,
46    /// American Dollar
47    USD,
48    /// South African Rands
49    ZAR,
50    /// Used when currency can be empty.
51    EMPTY,
52}
53
54impl fmt::Display for Currency {
55    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
56        let currency = match self {
57            Currency::NGN => "NGN",
58            Currency::GHS => "GHS",
59            Currency::USD => "USD",
60            Currency::ZAR => "ZAR",
61            Currency::EMPTY => "",
62        };
63        write!(f, "{}", currency)
64    }
65}