xapi_shared/data/
crypto_symbol.rs

1use serde::{Deserialize, Serialize};
2use std::fmt::{Display, Formatter};
3
4#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
5pub struct CryptoSymbol(String);
6
7impl CryptoSymbol {
8    pub fn new(symbol: impl Into<String>) -> Self {
9        Self(symbol.into())
10    }
11
12    pub fn as_str(&self) -> &str {
13        &self.0
14    }
15}
16
17impl From<String> for CryptoSymbol {
18    fn from(s: String) -> Self {
19        CryptoSymbol(s)
20    }
21}
22
23impl From<&str> for CryptoSymbol {
24    fn from(s: &str) -> Self {
25        CryptoSymbol(s.to_string())
26    }
27}
28
29impl Display for CryptoSymbol {
30    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
31        self.0.fmt(f)
32    }
33}