Add core::iter::once_with
This commit is contained in:
parent
75a369c5b1
commit
04c74f46f0
5 changed files with 129 additions and 0 deletions
|
@ -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>();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue