use super::Exchange;
impl core::fmt::Display for Exchange {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str(self.as_str())
}
}
impl core::str::FromStr for Exchange {
type Err = ParseExchangeError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Exchange::ALL
.iter()
.copied()
.find(|exchange| exchange.as_str() == s)
.ok_or_else(|| ParseExchangeError { input: s.into() })
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParseExchangeError {
input: Box<str>,
}
impl ParseExchangeError {
#[must_use]
pub fn input(&self) -> &str {
&self.input
}
}
impl core::fmt::Display for ParseExchangeError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(
f,
"{:?} is not a known exchange name; expected a snake_case name such as \"cme\" or \"nyse_arca\"",
self.input
)
}
}
impl std::error::Error for ParseExchangeError {}