aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/method.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/encoding/method.rs')
-rw-r--r--src/encoding/method.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/encoding/method.rs b/src/encoding/method.rs
index 5f8110a..73829b0 100644
--- a/src/encoding/method.rs
+++ b/src/encoding/method.rs
@@ -1,5 +1,7 @@
-use std::fmt::Display;
+use anyhow::bail;
+use std::{fmt::Display, str::FromStr};
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Method {
Register,
Invite,
@@ -21,3 +23,17 @@ impl Display for Method {
})
}
}
+impl FromStr for Method {
+ type Err = anyhow::Error;
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ Ok(match s {
+ "REGISTER" => Method::Register,
+ "INVITE" => Method::Invite,
+ "ACK" => Method::Ack,
+ "OPTION" => Method::Option,
+ "CANCEL" => Method::Cancel,
+ "BYE" => Method::Bye,
+ _ => bail!("unknown method"),
+ })
+ }
+}