-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #189 from sivizius/restructure-implementations
refactor(foreign): move implementations to dedicated, structured directory
- Loading branch information
Showing
46 changed files
with
1,592 additions
and
1,339 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use { | ||
crate::{size_hint, Arbitrary, Result, Unstructured}, | ||
std::borrow::{Cow, ToOwned}, | ||
}; | ||
|
||
impl<'a, A> Arbitrary<'a> for Cow<'a, A> | ||
where | ||
A: ToOwned + ?Sized, | ||
<A as ToOwned>::Owned: Arbitrary<'a>, | ||
{ | ||
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> { | ||
Arbitrary::arbitrary(u).map(Cow::Owned) | ||
} | ||
|
||
#[inline] | ||
fn size_hint(depth: usize) -> (usize, Option<usize>) { | ||
size_hint::recursion_guard(depth, |depth| { | ||
<<A as ToOwned>::Owned as Arbitrary>::size_hint(depth) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use { | ||
crate::{size_hint, Arbitrary, Result, Unstructured}, | ||
std::boxed::Box, | ||
}; | ||
|
||
impl<'a, A> Arbitrary<'a> for Box<A> | ||
where | ||
A: Arbitrary<'a>, | ||
{ | ||
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> { | ||
Arbitrary::arbitrary(u).map(Self::new) | ||
} | ||
|
||
#[inline] | ||
fn size_hint(depth: usize) -> (usize, Option<usize>) { | ||
size_hint::recursion_guard(depth, <A as Arbitrary>::size_hint) | ||
} | ||
} | ||
|
||
impl<'a, A> Arbitrary<'a> for Box<[A]> | ||
where | ||
A: Arbitrary<'a>, | ||
{ | ||
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> { | ||
u.arbitrary_iter()?.collect() | ||
} | ||
|
||
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self> { | ||
u.arbitrary_take_rest_iter()?.collect() | ||
} | ||
|
||
#[inline] | ||
fn size_hint(_depth: usize) -> (usize, Option<usize>) { | ||
(0, None) | ||
} | ||
} | ||
|
||
impl<'a> Arbitrary<'a> for Box<str> { | ||
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> { | ||
<String as Arbitrary>::arbitrary(u).map(|x| x.into_boxed_str()) | ||
} | ||
|
||
#[inline] | ||
fn size_hint(depth: usize) -> (usize, Option<usize>) { | ||
<String as Arbitrary>::size_hint(depth) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use { | ||
crate::{Arbitrary, Result, Unstructured}, | ||
std::collections::binary_heap::BinaryHeap, | ||
}; | ||
|
||
impl<'a, A> Arbitrary<'a> for BinaryHeap<A> | ||
where | ||
A: Arbitrary<'a> + Ord, | ||
{ | ||
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> { | ||
u.arbitrary_iter()?.collect() | ||
} | ||
|
||
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self> { | ||
u.arbitrary_take_rest_iter()?.collect() | ||
} | ||
|
||
#[inline] | ||
fn size_hint(_depth: usize) -> (usize, Option<usize>) { | ||
(0, None) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use { | ||
crate::{Arbitrary, Result, Unstructured}, | ||
std::collections::btree_map::BTreeMap, | ||
}; | ||
|
||
impl<'a, K, V> Arbitrary<'a> for BTreeMap<K, V> | ||
where | ||
K: Arbitrary<'a> + Ord, | ||
V: Arbitrary<'a>, | ||
{ | ||
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> { | ||
u.arbitrary_iter()?.collect() | ||
} | ||
|
||
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self> { | ||
u.arbitrary_take_rest_iter()?.collect() | ||
} | ||
|
||
#[inline] | ||
fn size_hint(_depth: usize) -> (usize, Option<usize>) { | ||
(0, None) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use { | ||
crate::{Arbitrary, Result, Unstructured}, | ||
std::collections::btree_set::BTreeSet, | ||
}; | ||
|
||
impl<'a, A> Arbitrary<'a> for BTreeSet<A> | ||
where | ||
A: Arbitrary<'a> + Ord, | ||
{ | ||
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> { | ||
u.arbitrary_iter()?.collect() | ||
} | ||
|
||
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self> { | ||
u.arbitrary_take_rest_iter()?.collect() | ||
} | ||
|
||
#[inline] | ||
fn size_hint(_depth: usize) -> (usize, Option<usize>) { | ||
(0, None) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use { | ||
crate::{Arbitrary, Result, Unstructured}, | ||
std::collections::linked_list::LinkedList, | ||
}; | ||
|
||
impl<'a, A> Arbitrary<'a> for LinkedList<A> | ||
where | ||
A: Arbitrary<'a>, | ||
{ | ||
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> { | ||
u.arbitrary_iter()?.collect() | ||
} | ||
|
||
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self> { | ||
u.arbitrary_take_rest_iter()?.collect() | ||
} | ||
|
||
#[inline] | ||
fn size_hint(_depth: usize) -> (usize, Option<usize>) { | ||
(0, None) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
mod binary_heap; | ||
mod btree_map; | ||
mod btree_set; | ||
mod linked_list; | ||
mod vec_deque; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use { | ||
crate::{Arbitrary, Result, Unstructured}, | ||
std::collections::vec_deque::VecDeque, | ||
}; | ||
|
||
impl<'a, A> Arbitrary<'a> for VecDeque<A> | ||
where | ||
A: Arbitrary<'a>, | ||
{ | ||
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> { | ||
u.arbitrary_iter()?.collect() | ||
} | ||
|
||
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self> { | ||
u.arbitrary_take_rest_iter()?.collect() | ||
} | ||
|
||
#[inline] | ||
fn size_hint(_depth: usize) -> (usize, Option<usize>) { | ||
(0, None) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use { | ||
crate::{Arbitrary, Result, Unstructured}, | ||
std::ffi::CString, | ||
}; | ||
|
||
impl<'a> Arbitrary<'a> for CString { | ||
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> { | ||
<Vec<u8> as Arbitrary>::arbitrary(u).map(|mut x| { | ||
x.retain(|&c| c != 0); | ||
// SAFETY: all zero bytes have been removed | ||
unsafe { Self::from_vec_unchecked(x) } | ||
}) | ||
} | ||
|
||
#[inline] | ||
fn size_hint(depth: usize) -> (usize, Option<usize>) { | ||
<Vec<u8> as Arbitrary>::size_hint(depth) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mod c_str; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//! Implementations of [`Arbitrary`] for [`alloc`] types, | ||
//! excluding those in [`core`]. | ||
//! | ||
//! [`Arbitrary`]: crate::Arbitrary | ||
mod borrow; | ||
mod boxed; | ||
mod collections; | ||
mod ffi; | ||
mod rc; | ||
mod string; | ||
mod sync; | ||
mod vec; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use { | ||
crate::{size_hint, Arbitrary, Result, Unstructured}, | ||
std::rc::Rc, | ||
}; | ||
|
||
impl<'a, A> Arbitrary<'a> for Rc<A> | ||
where | ||
A: Arbitrary<'a>, | ||
{ | ||
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> { | ||
Arbitrary::arbitrary(u).map(Self::new) | ||
} | ||
|
||
#[inline] | ||
fn size_hint(depth: usize) -> (usize, Option<usize>) { | ||
size_hint::recursion_guard(depth, <A as Arbitrary>::size_hint) | ||
} | ||
} | ||
|
||
impl<'a, A> Arbitrary<'a> for Rc<[A]> | ||
where | ||
A: Arbitrary<'a>, | ||
{ | ||
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> { | ||
u.arbitrary_iter()?.collect() | ||
} | ||
|
||
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self> { | ||
u.arbitrary_take_rest_iter()?.collect() | ||
} | ||
|
||
#[inline] | ||
fn size_hint(_depth: usize) -> (usize, Option<usize>) { | ||
(0, None) | ||
} | ||
} | ||
|
||
impl<'a> Arbitrary<'a> for Rc<str> { | ||
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> { | ||
<&str as Arbitrary>::arbitrary(u).map(Into::into) | ||
} | ||
|
||
#[inline] | ||
fn size_hint(depth: usize) -> (usize, Option<usize>) { | ||
<&str as Arbitrary>::size_hint(depth) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use { | ||
crate::{Arbitrary, Result, Unstructured}, | ||
std::string::String, | ||
}; | ||
|
||
impl<'a> Arbitrary<'a> for String { | ||
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> { | ||
<&str as Arbitrary>::arbitrary(u).map(Into::into) | ||
} | ||
|
||
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self> { | ||
<&str as Arbitrary>::arbitrary_take_rest(u).map(Into::into) | ||
} | ||
|
||
#[inline] | ||
fn size_hint(depth: usize) -> (usize, Option<usize>) { | ||
<&str as Arbitrary>::size_hint(depth) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use { | ||
crate::{size_hint, Arbitrary, Result, Unstructured}, | ||
std::sync::Arc, | ||
}; | ||
|
||
impl<'a, A> Arbitrary<'a> for Arc<A> | ||
where | ||
A: Arbitrary<'a>, | ||
{ | ||
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> { | ||
Arbitrary::arbitrary(u).map(Self::new) | ||
} | ||
|
||
#[inline] | ||
fn size_hint(depth: usize) -> (usize, Option<usize>) { | ||
size_hint::recursion_guard(depth, <A as Arbitrary>::size_hint) | ||
} | ||
} | ||
|
||
impl<'a, A> Arbitrary<'a> for Arc<[A]> | ||
where | ||
A: Arbitrary<'a>, | ||
{ | ||
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> { | ||
u.arbitrary_iter()?.collect() | ||
} | ||
|
||
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self> { | ||
u.arbitrary_take_rest_iter()?.collect() | ||
} | ||
|
||
#[inline] | ||
fn size_hint(_depth: usize) -> (usize, Option<usize>) { | ||
(0, None) | ||
} | ||
} | ||
|
||
impl<'a> Arbitrary<'a> for Arc<str> { | ||
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> { | ||
<&str as Arbitrary>::arbitrary(u).map(Into::into) | ||
} | ||
|
||
#[inline] | ||
fn size_hint(depth: usize) -> (usize, Option<usize>) { | ||
<&str as Arbitrary>::size_hint(depth) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use { | ||
crate::{Arbitrary, Result, Unstructured}, | ||
std::vec::Vec, | ||
}; | ||
|
||
impl<'a, A> Arbitrary<'a> for Vec<A> | ||
where | ||
A: Arbitrary<'a>, | ||
{ | ||
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> { | ||
u.arbitrary_iter()?.collect() | ||
} | ||
|
||
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self> { | ||
u.arbitrary_take_rest_iter()?.collect() | ||
} | ||
|
||
#[inline] | ||
fn size_hint(_depth: usize) -> (usize, Option<usize>) { | ||
(0, None) | ||
} | ||
} |
Oops, something went wrong.