Unnamed repository; edit this file 'description' to name the repository.
Merge rust-analyzer/smol_str#35
35: Implement arbitrary behind a feature flag r=matklad a=jeffa5 Fixes rust-analyzer/smol_str#34 Co-authored-by: Andrew Jeffery <[email protected]>
bors[bot] 2021-06-26
parent 4966a00 · parent cfe2277 · commit 5ac6301
-rw-r--r--lib/smol_str/Cargo.toml3
-rw-r--r--lib/smol_str/src/lib.rs8
2 files changed, 10 insertions, 1 deletions
diff --git a/lib/smol_str/Cargo.toml b/lib/smol_str/Cargo.toml
index fee00ec2ba..fe2497cfd6 100644
--- a/lib/smol_str/Cargo.toml
+++ b/lib/smol_str/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "smol_str"
-version = "0.1.17"
+version = "0.1.18"
description = "small-string optimized string type with O(1) clone"
license = "MIT OR Apache-2.0"
repository = "https://github.com/matklad/smol_str"
@@ -9,6 +9,7 @@ edition = "2018"
[dependencies]
serde = { version = "1", optional = true, default_features = false, features = [ "std" ] }
+arbitrary = { version = "1", optional = true }
[dev-dependencies]
proptest = "0.10"
diff --git a/lib/smol_str/src/lib.rs b/lib/smol_str/src/lib.rs
index 6136878b3e..1583dfe077 100644
--- a/lib/smol_str/src/lib.rs
+++ b/lib/smol_str/src/lib.rs
@@ -300,6 +300,14 @@ impl Borrow<str> for SmolStr {
}
}
+#[cfg(feature = "arbitrary")]
+impl<'a> arbitrary::Arbitrary<'a> for SmolStr {
+ fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> Result<Self, arbitrary::Error> {
+ let s = <&str>::arbitrary(u)?;
+ Ok(SmolStr::new(s))
+ }
+}
+
const INLINE_CAP: usize = 22;
const N_NEWLINES: usize = 32;
const N_SPACES: usize = 128;