Skip to content

Commit

Permalink
Impl 'TryFrom<&str>' for 'Method'.
Browse files Browse the repository at this point in the history
Also implements 'From<Infallible>' for 'ParseMethodError'.
  • Loading branch information
SergioBenitez committed Aug 17, 2024
1 parent 4c71ed6 commit ef1cfa0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions core/http/src/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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()
Expand Down

0 comments on commit ef1cfa0

Please sign in to comment.