Skip to content

Commit

Permalink
Implement FromStr for IString (#21)
Browse files Browse the repository at this point in the history
Co-authored-by: Cecile Tonglet <cecile.tonglet@cecton.com>
  • Loading branch information
uzytkownik and cecton authored Jul 30, 2023
1 parent a5ead43 commit 6d6a228
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/string.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::borrow::Cow;
use std::fmt::Debug;
use std::str::FromStr;

/// An immutable string type inspired by [Immutable.js](https://immutable-js.com/).
///
Expand Down Expand Up @@ -147,6 +148,13 @@ impl std::borrow::Borrow<str> for IString {
}
}

impl FromStr for IString {
type Err = std::convert::Infallible;
fn from_str(value: &str) -> Result<Self, Self::Err> {
Ok(IString::from(String::from(value)))
}
}

#[cfg(feature = "serde")]
impl serde::Serialize for IString {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
Expand Down

0 comments on commit 6d6a228

Please sign in to comment.