use serde::{Deserialize, Serialize};
use std::fmt;
use std::sync::Arc;
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Currency(Arc<str>);
impl Currency {
pub fn new(code: impl Into<String>) -> Self {
Self(Arc::from(code.into().to_uppercase().as_str()))
}
pub fn code(&self) -> &str {
&self.0
}
}
impl fmt::Display for Currency {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", &*self.0)
}
}
impl From<&str> for Currency {
fn from(s: &str) -> Self {
Self::new(s)
}
}
#[cfg(test)]
#[path = "currency_tests.rs"]
mod tests;