Add support for arbitrary

This commit is contained in:
Andrew Sun
2022-01-13 01:40:47 -05:00
parent 7cbb3b1fa1
commit 9bcd950f25
3 changed files with 23 additions and 0 deletions
+1
View File
@@ -21,6 +21,7 @@ may_dangle = []
[dependencies]
serde = { version = "1", optional = true, default-features = false }
arbitrary = { version = "1", optional = true }
[dev_dependencies]
bincode = "1.0.1"
+19
View File
@@ -0,0 +1,19 @@
use crate::{Array, SmallVec};
use arbitrary::{Arbitrary, Unstructured};
impl<'a, A: Array> Arbitrary<'a> for SmallVec<A>
where
<A as Array>::Item: Arbitrary<'a>,
{
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
u.arbitrary_iter()?.collect()
}
fn arbitrary_take_rest(u: Unstructured<'a>) -> arbitrary::Result<Self> {
u.arbitrary_take_rest_iter()?.collect()
}
fn size_hint(depth: usize) -> (usize, Option<usize>) {
arbitrary::size_hint::and(<usize as Arbitrary>::size_hint(depth), (0, None))
}
}
+3
View File
@@ -1651,6 +1651,9 @@ trait SpecFrom<A: Array, S> {
#[cfg(feature = "specialization")]
mod specialization;
#[cfg(feature = "arbitrary")]
mod arbitrary;
#[cfg(feature = "specialization")]
impl<'a, A: Array> SpecFrom<A, &'a [A::Item]> for SmallVec<A>
where