Skip to content

Commit

Permalink
Merge pull request #18 from dalegaard/feature_fromstr
Browse files Browse the repository at this point in the history
Implement FromStr
  • Loading branch information
epage authored Nov 5, 2021
2 parents 8f4e6dd + 6f35b13 commit f586cd0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/cow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,14 @@ impl<'s> From<&'s str> for KStringCow<'s> {
}
}

impl std::str::FromStr for KStringCow<'_> {
type Err = std::convert::Infallible;
#[inline]
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self::from_string(s.into()))
}
}

#[cfg(feature = "serde")]
impl<'s> serde::Serialize for KStringCow<'s> {
#[inline]
Expand Down
8 changes: 8 additions & 0 deletions src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,14 @@ impl From<&'static str> for KString {
}
}

impl std::str::FromStr for KString {
type Err = std::convert::Infallible;
#[inline]
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(KString::from_ref(s))
}
}

#[cfg(feature = "serde")]
impl serde::Serialize for KString {
#[inline]
Expand Down

0 comments on commit f586cd0

Please sign in to comment.