Impl 'TryFrom<&str>' for 'Method'.

Also implements 'From<Infallible>' for 'ParseMethodError'.
This commit is contained in:
Sergio Benitez 2024-08-17 04:25:15 -07:00
parent 4c71ed6ee3
commit ef1cfa0965
1 changed files with 14 additions and 0 deletions

View File

@ -316,6 +316,12 @@ pub struct ParseMethodError;
impl std::error::Error for ParseMethodError { }
impl From<std::convert::Infallible> for ParseMethodError {
fn from(infallible: std::convert::Infallible) -> Self {
match infallible {}
}
}
impl fmt::Display for ParseMethodError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("invalid HTTP method")
@ -331,6 +337,14 @@ impl FromStr for Method {
}
}
impl TryFrom<&str> for Method {
type Error = ParseMethodError;
fn try_from(s: &str) -> Result<Self, Self::Error> {
Self::try_from(s.as_bytes())
}
}
impl AsRef<str> for Method {
fn as_ref(&self) -> &str {
self.as_str()