df_hyperliquid_core/markets/
dex.rs1#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
6pub enum Dex<'a> {
7 #[default]
9 Main,
10 Hip3(&'a str),
12}
13
14impl<'a> Dex<'a> {
15 #[must_use]
17 pub fn of_coin(coin: &'a str) -> Dex<'a> {
18 match coin.split_once(':') {
19 Some((dex, _)) => Dex::Hip3(dex),
20 None => Dex::Main,
21 }
22 }
23
24 #[must_use]
26 pub const fn name(self) -> Option<&'a str> {
27 match self {
28 Dex::Main => None,
29 Dex::Hip3(name) => Some(name),
30 }
31 }
32}
33
34#[must_use]
36pub fn split_coin(coin: &str) -> Option<(&str, &str)> {
37 let (dex, symbol) = coin.split_once(':')?;
38 (!dex.is_empty() && !symbol.is_empty()).then_some((dex, symbol))
39}
40
41#[must_use]
43pub fn coin(dex: &str, symbol: &str) -> String {
44 format!("{dex}:{symbol}")
45}
46
47#[cfg(test)]
48#[path = "tests/dex.rs"]
49mod tests;