use anyhow::bail; use std::{fmt::Display, str::FromStr}; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum Method { Register, Invite, Ack, Options, Cancel, Bye, } impl Display for Method { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(match self { Method::Register => "REGISTER", Method::Invite => "INVITE", Method::Ack => "ACK", Method::Options => "OPTIONS", Method::Cancel => "CANCEL", Method::Bye => "BYE", }) } } impl FromStr for Method { type Err = anyhow::Error; fn from_str(s: &str) -> Result { Ok(match s { "REGISTER" => Method::Register, "INVITE" => Method::Invite, "ACK" => Method::Ack, "OPTIONS" => Method::Options, "CANCEL" => Method::Cancel, "BYE" => Method::Bye, _ => bail!("unknown method"), }) } }