Skip to content

Commit 428c2f5

Browse files
bors[bot]Andrew Jeffery
andauthored
35: Implement arbitrary behind a feature flag r=matklad a=jeffa5 Fixes rust-analyzer/smol_str#34 Co-authored-by: Andrew Jeffery <dev@jeffas.io>
2 parents 7e76690 + 7994418 commit 428c2f5

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/tools/rust-analyzer/lib/smol_str/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "smol_str"
3-
version = "0.1.17"
3+
version = "0.1.18"
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"
@@ -9,6 +9,7 @@ edition = "2018"
99

1010
[dependencies]
1111
serde = { version = "1", optional = true, default_features = false, features = [ "std" ] }
12+
arbitrary = { version = "1", optional = true }
1213

1314
[dev-dependencies]
1415
proptest = "0.10"

src/tools/rust-analyzer/lib/smol_str/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,14 @@ impl Borrow<str> for SmolStr {
300300
}
301301
}
302302

303+
#[cfg(feature = "arbitrary")]
304+
impl<'a> arbitrary::Arbitrary<'a> for SmolStr {
305+
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> Result<Self, arbitrary::Error> {
306+
let s = <&str>::arbitrary(u)?;
307+
Ok(SmolStr::new(s))
308+
}
309+
}
310+
303311
const INLINE_CAP: usize = 22;
304312
const N_NEWLINES: usize = 32;
305313
const N_SPACES: usize = 128;

0 commit comments

Comments
 (0)