forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly forward
ByRefSized::fold
to the inner iterator
- Loading branch information
Showing
3 changed files
with
38 additions
and
12 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
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,20 @@ | ||
use core::iter::*; | ||
|
||
#[test] | ||
fn test_iterator_by_ref_sized() { | ||
let a = ['a', 'b', 'c', 'd']; | ||
|
||
let mut s = String::from("Z"); | ||
let mut it = a.iter().copied(); | ||
ByRefSized(&mut it).take(2).for_each(|x| s.push(x)); | ||
assert_eq!(s, "Zab"); | ||
ByRefSized(&mut it).fold((), |(), x| s.push(x)); | ||
assert_eq!(s, "Zabcd"); | ||
|
||
let mut s = String::from("Z"); | ||
let mut it = a.iter().copied(); | ||
ByRefSized(&mut it).rev().take(2).for_each(|x| s.push(x)); | ||
assert_eq!(s, "Zdc"); | ||
ByRefSized(&mut it).rfold((), |(), x| s.push(x)); | ||
assert_eq!(s, "Zdcba"); | ||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
mod array_chunks; | ||
mod by_ref_sized; | ||
mod chain; | ||
mod cloned; | ||
mod copied; | ||
|