Skip to content

Commit d094d34

Browse files
authored
Merge pull request #95 from LukeMathWalker/try-from-header-value
Implement TryFrom<&'a str> for HeaderValue and Method
2 parents c2f0819 + 302fb04 commit d094d34

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/headers/header_value.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ impl FromStr for HeaderValue {
8282
}
8383
}
8484

85+
impl<'a> std::convert::TryFrom<&'a str> for HeaderValue {
86+
type Error = Error;
87+
88+
fn try_from(value: &'a str) -> Result<Self, Self::Error> {
89+
Self::from_str(value)
90+
}
91+
}
92+
8593
impl Display for HeaderValue {
8694
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8795
write!(f, "{}", self.inner)

src/method.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,11 @@ impl FromStr for Method {
8484
}
8585
}
8686
}
87+
88+
impl<'a> std::convert::TryFrom<&'a str> for Method {
89+
type Error = crate::Error;
90+
91+
fn try_from(value: &'a str) -> Result<Self, Self::Error> {
92+
Self::from_str(value)
93+
}
94+
}

0 commit comments

Comments
 (0)