Skip to content

Commit 7562c45

Browse files
committed
Use std::iter::empty inside empty_shrinker
The `empty` iterator is a zero sized type, and this way the empty shrinker (also the default shrinker) uses no allocation at all. empty and once require Rust 1.2 or later.
1 parent fb2ed7b commit 7562c45

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/arbitrary.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::collections::{
99
VecDeque,
1010
};
1111
use std::hash::Hash;
12+
use std::iter::{empty, once};
1213
use std::ops::{Range, RangeFrom, RangeTo, RangeFull};
1314
use entropy_pool::EntropyPool;
1415
use shrink::{Shrinker, StdShrinker};
@@ -113,12 +114,12 @@ impl<R: Rng> Gen for StdGen<R> {
113114

114115
/// Creates a shrinker with zero elements.
115116
pub fn empty_shrinker<A: 'static>() -> Box<Iterator<Item=A>> {
116-
Box::new(None.into_iter())
117+
Box::new(empty())
117118
}
118119

119120
/// Creates a shrinker with a single element.
120121
pub fn single_shrinker<A: 'static>(value: A) -> Box<Iterator<Item=A>> {
121-
Box::new(Some(value).into_iter())
122+
Box::new(once(value))
122123
}
123124

124125
/// `Arbitrary` describes types whose values can be randomly generated and

0 commit comments

Comments
 (0)