paystack/models/currency_models.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/// - `KES`: Kenya Shilling.
22/// - `XOF`: West African CFA Franc.
23/// - `EMPTY`: Used when the currency can be empty.
24///
25/// # Examples
26///
27/// ```
28/// use paystack::Currency;
29///
30/// let ngn = Currency::NGN;
31/// let ghs = Currency::GHS;
32/// let usd = Currency::USD;
33/// let zar = Currency::ZAR;
34/// let kes = Currency::KES;
35/// let xof = Currency::XOF;
36/// let empty = Currency::EMPTY;
37///
38/// println!("{:?}", ngn); // Prints: NGN
39/// ```
40///
41/// The example demonstrates the usage of the `Currency` enum from the Paystack crate,
42/// creating instances of each variant and printing a debug representation.
43#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq)]
44pub enum Currency {
45 /// Nigerian Naira
46 #[default]
47 NGN,
48 /// Ghanaian Cedis
49 GHS,
50 /// American Dollar
51 USD,
52 /// South African Rands
53 ZAR,
54 /// Kenya Shilling
55 KES,
56 /// West African CFA Franc
57 XOF,
58 /// Used when currency can be empty.
59 EMPTY,
60}
61
62impl fmt::Display for Currency {
63 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
64 let currency = match self {
65 Currency::NGN => "NGN",
66 Currency::GHS => "GHS",
67 Currency::USD => "USD",
68 Currency::ZAR => "ZAR",
69 Currency::KES => "KES",
70 Currency::XOF => "XOF",
71 Currency::EMPTY => "",
72 };
73 write!(f, "{currency}")
74 }
75}