alpaca_data/common/
enums.rs1use std::fmt::{self, Display, Formatter};
2
3#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
4pub enum Sort {
5 #[default]
6 Asc,
7 Desc,
8}
9
10impl Display for Sort {
11 fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
12 formatter.write_str(match self {
13 Self::Asc => "asc",
14 Self::Desc => "desc",
15 })
16 }
17}
18
19#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize)]
20#[serde(transparent)]
21pub struct Currency(String);
22
23impl Currency {
24 pub fn usd() -> Self {
25 Self::from("USD")
26 }
27
28 pub fn as_str(&self) -> &str {
29 &self.0
30 }
31}
32
33impl Default for Currency {
34 fn default() -> Self {
35 Self::usd()
36 }
37}
38
39impl From<&str> for Currency {
40 fn from(value: &str) -> Self {
41 Self(value.to_string())
42 }
43}
44
45impl From<String> for Currency {
46 fn from(value: String) -> Self {
47 Self(value)
48 }
49}
50
51impl Display for Currency {
52 fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
53 formatter.write_str(self.as_str())
54 }
55}