From ef1cfa0965a8a1ed67a68c35897b6dbb020a1224 Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Sat, 17 Aug 2024 04:25:15 -0700 Subject: [PATCH] Impl 'TryFrom<&str>' for 'Method'. Also implements 'From' for 'ParseMethodError'. --- core/http/src/method.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/http/src/method.rs b/core/http/src/method.rs index cf6129ea..2b273181 100644 --- a/core/http/src/method.rs +++ b/core/http/src/method.rs @@ -316,6 +316,12 @@ pub struct ParseMethodError; impl std::error::Error for ParseMethodError { } +impl From 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::try_from(s.as_bytes()) + } +} + impl AsRef for Method { fn as_ref(&self) -> &str { self.as_str()