Skip to content

Commit b6dde67

Browse files
committed
Impl 'TryFrom<&str>' for 'Method'.
Also implements 'From<Infallible>' for 'ParseMethodError'.
1 parent e8b6076 commit b6dde67

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

core/http/src/method.rs

+14
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,12 @@ pub struct ParseMethodError;
316316

317317
impl std::error::Error for ParseMethodError { }
318318

319+
impl From<std::convert::Infallible> for ParseMethodError {
320+
fn from(infallible: std::convert::Infallible) -> Self {
321+
match infallible {}
322+
}
323+
}
324+
319325
impl fmt::Display for ParseMethodError {
320326
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
321327
f.write_str("invalid HTTP method")
@@ -331,6 +337,14 @@ impl FromStr for Method {
331337
}
332338
}
333339

340+
impl TryFrom<&str> for Method {
341+
type Error = ParseMethodError;
342+
343+
fn try_from(s: &str) -> Result<Self, Self::Error> {
344+
Self::try_from(s.as_bytes())
345+
}
346+
}
347+
334348
impl AsRef<str> for Method {
335349
fn as_ref(&self) -> &str {
336350
self.as_str()

0 commit comments

Comments
 (0)