use bitcode::{Decode, Encode};
#[derive(Debug, Clone, PartialEq, Encode, Decode)]
pub enum Direction {
Buy,
Sell,
}
impl Direction {
pub fn to_str(&self) -> &'static str {
match self {
Direction::Buy => "b",
Direction::Sell => "s",
}
}
}
impl std::fmt::Display for Direction {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Buy => write!(f, "Buy"),
Self::Sell => write!(f, "Sell"),
}
}
}
impl From<&str> for Direction {
fn from(value: &str) -> Self {
match value {
"b" => Direction::Buy,
"s" => Direction::Sell,
"B" => Direction::Buy,
"S" => Direction::Sell,
_ => panic!("Invalid value for direction: {value}"),
}
}
}