nautilus_binance/common/sbe/spot/
rate_limit_interval.rs

1#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
2#[repr(u8)]
3pub enum RateLimitInterval {
4    Second = 0x0_u8,
5    Minute = 0x1_u8,
6    Hour = 0x2_u8,
7    Day = 0x3_u8,
8    NonRepresentable = 0xfe_u8,
9    #[default]
10    NullVal = 0xff_u8,
11}
12impl From<u8> for RateLimitInterval {
13    #[inline]
14    fn from(v: u8) -> Self {
15        match v {
16            0x0_u8 => Self::Second,
17            0x1_u8 => Self::Minute,
18            0x2_u8 => Self::Hour,
19            0x3_u8 => Self::Day,
20            0xfe_u8 => Self::NonRepresentable,
21            _ => Self::NullVal,
22        }
23    }
24}
25impl From<RateLimitInterval> for u8 {
26    #[inline]
27    fn from(v: RateLimitInterval) -> Self {
28        match v {
29            RateLimitInterval::Second => 0x0_u8,
30            RateLimitInterval::Minute => 0x1_u8,
31            RateLimitInterval::Hour => 0x2_u8,
32            RateLimitInterval::Day => 0x3_u8,
33            RateLimitInterval::NonRepresentable => 0xfe_u8,
34            RateLimitInterval::NullVal => 0xff_u8,
35        }
36    }
37}
38impl core::str::FromStr for RateLimitInterval {
39    type Err = ();
40
41    #[inline]
42    fn from_str(v: &str) -> core::result::Result<Self, Self::Err> {
43        match v {
44            "Second" => Ok(Self::Second),
45            "Minute" => Ok(Self::Minute),
46            "Hour" => Ok(Self::Hour),
47            "Day" => Ok(Self::Day),
48            "NonRepresentable" => Ok(Self::NonRepresentable),
49            _ => Ok(Self::NullVal),
50        }
51    }
52}
53impl core::fmt::Display for RateLimitInterval {
54    #[inline]
55    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
56        match self {
57            Self::Second => write!(f, "Second"),
58            Self::Minute => write!(f, "Minute"),
59            Self::Hour => write!(f, "Hour"),
60            Self::Day => write!(f, "Day"),
61            Self::NonRepresentable => write!(f, "NonRepresentable"),
62            Self::NullVal => write!(f, "NullVal"),
63        }
64    }
65}