I've got an enum with a From impl:
pub enum OrderType {
Market = 0,
Limit = 1,
}
impl From<&str> for OrderType {
fn from(order_type: &str) -> Self {
match order_type {
"MARKET" => OrderType::Market,
"LIMIT" => OrderType::Limit,
_ => {
error!("Unknown order type: {}", order_type);
OrderType::Market
}
}
}
Like all Rust developers, I've read one million times that if you impl From you don't need to impl Into. So I tried this:
let str: &str = order.order_type.into();
which fails to compile with
= help: the trait `From<domain::OrderType>` is not implemented for `&str`
but trait `From<mime::Name<'_>>` is implemented for it
= help: for that trait implementation, expected `mime::Name<'_>`, found `domain::OrderType`
= note: required for `domain::OrderType` to implement `Into<&str>`
unless I also impl Into:
impl Into<&str> for OrderType {
fn into(self) -> &'static str {
match self {
OrderType::Market => "MARKET",
OrderType::Limit => "LIMIT",
}
}
}
Thus, I am confused.