Unnamed repository; edit this file 'description' to name the repository.
Merge rust-analyzer/smol_str#39
39: implement FromStr r=matklad a=matklad
closes rust-analyzer/smol_str#31
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
| -rw-r--r-- | lib/smol_str/Cargo.toml | 2 | ||||
| -rw-r--r-- | lib/smol_str/src/lib.rs | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/lib/smol_str/Cargo.toml b/lib/smol_str/Cargo.toml index f9c3a350f2..d00ca31123 100644 --- a/lib/smol_str/Cargo.toml +++ b/lib/smol_str/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "smol_str" -version = "0.1.18" +version = "0.1.19" description = "small-string optimized string type with O(1) clone" license = "MIT OR Apache-2.0" repository = "https://github.com/matklad/smol_str" diff --git a/lib/smol_str/src/lib.rs b/lib/smol_str/src/lib.rs index 9f99153f2a..d819fe2dd9 100644 --- a/lib/smol_str/src/lib.rs +++ b/lib/smol_str/src/lib.rs @@ -6,11 +6,13 @@ extern crate core as std; #[cfg(not(feature = "std"))] extern crate alloc; +use core::convert::Infallible; use std::{ borrow::Borrow, cmp::{self, Ordering}, fmt, hash, iter, ops::Deref, + str::FromStr, }; #[cfg(not(feature = "std"))] @@ -316,6 +318,15 @@ impl Borrow<str> for SmolStr { } } +impl FromStr for SmolStr { + type Err = Infallible; + + #[inline] + fn from_str(s: &str) -> Result<SmolStr, Self::Err> { + Ok(SmolStr::from(s)) + } +} + #[cfg(feature = "arbitrary")] impl<'a> arbitrary::Arbitrary<'a> for SmolStr { fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> Result<Self, arbitrary::Error> { |