Skip to content

Commit 56eaef5

Browse files
bors[bot]matklad
andauthored
39: implement FromStr r=matklad a=matklad closes rust-lang#31 bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents f613f52 + e3edb41 commit 56eaef5

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "smol_str"
3-
version = "0.1.18"
3+
version = "0.1.19"
44
description = "small-string optimized string type with O(1) clone"
55
license = "MIT OR Apache-2.0"
66
repository = "https://github.com/matklad/smol_str"

src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ extern crate core as std;
66
#[cfg(not(feature = "std"))]
77
extern crate alloc;
88

9+
use core::convert::Infallible;
910
use std::{
1011
borrow::Borrow,
1112
cmp::{self, Ordering},
1213
fmt, hash, iter,
1314
ops::Deref,
15+
str::FromStr,
1416
};
1517

1618
#[cfg(not(feature = "std"))]
@@ -316,6 +318,15 @@ impl Borrow<str> for SmolStr {
316318
}
317319
}
318320

321+
impl FromStr for SmolStr {
322+
type Err = Infallible;
323+
324+
#[inline]
325+
fn from_str(s: &str) -> Result<SmolStr, Self::Err> {
326+
Ok(SmolStr::from(s))
327+
}
328+
}
329+
319330
#[cfg(feature = "arbitrary")]
320331
impl<'a> arbitrary::Arbitrary<'a> for SmolStr {
321332
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> Result<Self, arbitrary::Error> {

0 commit comments

Comments
 (0)