1
Fork 0

Add core::iter::once_with

This commit is contained in:
Stjepan Glavina 2019-01-13 11:16:14 +01:00
parent 75a369c5b1
commit 04c74f46f0
5 changed files with 129 additions and 0 deletions

View file

@ -1906,6 +1906,23 @@ fn test_once() {
assert_eq!(it.next(), None);
}
#[test]
fn test_once_with() {
let mut count = 0;
let mut it = once_with(|| {
count += 1;
42
});
assert_eq!(count, 0);
assert_eq!(it.next(), Some(42));
assert_eq!(count, 1);
assert_eq!(it.next(), None);
assert_eq!(count, 1);
assert_eq!(it.next(), None);
assert_eq!(count, 1);
}
#[test]
fn test_empty() {
let mut it = empty::<i32>();