quant_primitives/
currency.rs1use serde::{Deserialize, Serialize};
4use std::fmt;
5use std::sync::Arc;
6
7#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
12pub struct Currency(Arc<str>);
13
14impl Currency {
15 pub fn new(code: impl Into<String>) -> Self {
17 Self(Arc::from(code.into().to_uppercase().as_str()))
18 }
19
20 pub fn code(&self) -> &str {
22 &self.0
23 }
24}
25
26impl fmt::Display for Currency {
27 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28 write!(f, "{}", &*self.0)
29 }
30}
31
32impl From<&str> for Currency {
33 fn from(s: &str) -> Self {
34 Self::new(s)
35 }
36}
37
38#[cfg(test)]
39#[path = "currency_tests.rs"]
40mod tests;