Skip to content

Commit

Permalink
feat: Implement FromStr
Browse files Browse the repository at this point in the history
This implements FromStr for `KString` and `KStringCow`.

Fixes cobalt-org#17.
  • Loading branch information
dalegaard committed Nov 5, 2021
1 parent 8f4e6dd commit 6f35b13
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 6f35b13

Please sign in to comment.