summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Kreutz <mail@skreutz.com>2023-02-07 18:01:47 +0100
committerStefan Kreutz <mail@skreutz.com>2023-02-07 18:01:47 +0100
commitac6ea8f1f6cd90502faee181dd054565802de4af (patch)
tree659646bc5d173535b374effadbc66f49fe2e0813
parentacb122c0fcb3757aef2dc31a4757c1215b2917cf (diff)
downloadparseq-ac6ea8f1f6cd90502faee181dd054565802de4af.tar
Remove useless conversion from Range into Iterator
-rw-r--r--src/lib.rs40
1 files changed, 14 insertions, 26 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 2d34b1c..3114426 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -10,7 +10,6 @@
//! use parseq::ParallelIterator;
//!
//! let mut iter = (0..3)
-//! .into_iter()
//! .map_parallel(|i| {
//! // Insert heavy computation here ...
//! std::thread::sleep(Duration::from_millis((i % 3) * 10));
@@ -73,7 +72,6 @@ pub trait ParallelIterator {
/// use parseq::ParallelIterator;
///
/// let mut iter = (0..3)
- /// .into_iter()
/// .map_parallel(|i| {
/// std::thread::sleep(Duration::from_millis((i % 3) * 10));
/// i
@@ -121,7 +119,6 @@ pub trait ParallelIterator {
/// use parseq::ParallelIterator;
///
/// let mut iter = (0..3)
- /// .into_iter()
/// .map_parallel_limit(2, 16, |i| {
/// std::thread::sleep(Duration::from_millis((i % 3) * 10));
/// i
@@ -365,45 +362,41 @@ mod tests {
#[test]
fn map_with_multiple_threads() {
assert!((0..100)
- .into_iter()
.map_parallel_limit(5, 7, |i| {
std::thread::sleep(Duration::from_millis((i % 3) * 10));
2 * i
})
- .eq((0..100).into_iter().map(|i| 2 * i)));
+ .eq((0..100).map(|i| 2 * i)));
}
#[test]
fn map_with_single_thread() {
assert!((0..100)
- .into_iter()
.map_parallel_limit(1, 7, |i| {
std::thread::sleep(Duration::from_millis((i % 3) * 10));
2 * i
})
- .eq((0..100).into_iter().map(|i| 2 * i)));
+ .eq((0..100).map(|i| 2 * i)));
}
#[test]
fn map_with_zero_threads() {
assert!((0..100)
- .into_iter()
.map_parallel_limit(0, 7, |i| {
std::thread::sleep(Duration::from_millis((i % 3) * 10));
2 * i
})
- .eq((0..100).into_iter().map(|i| 2 * i)));
+ .eq((0..100).map(|i| 2 * i)));
}
#[test]
fn map_with_zero_buffer_size() {
assert!((0..100)
- .into_iter()
.map_parallel_limit(5, 0, |i| {
std::thread::sleep(Duration::from_millis((i % 3) * 10));
2 * i
})
- .eq((0..100).into_iter().map(|i| 2 * i)));
+ .eq((0..100).map(|i| 2 * i)));
}
#[test]
@@ -428,9 +421,7 @@ mod tests {
#[test]
fn map_is_lazy() {
- let _iter = (0..10)
- .into_iter()
- .map_parallel_limit(5, 7, |_| panic!("eager evaluation"));
+ let _iter = (0..10).map_parallel_limit(5, 7, |_| panic!("eager evaluation"));
}
#[test]
@@ -438,7 +429,6 @@ mod tests {
#[ntest::timeout(1000)]
fn map_propagates_panic() {
let _ = (0..100)
- .into_iter()
.map_parallel_limit(5, 7, |i| {
if i == 13 {
panic!("boom");
@@ -480,7 +470,7 @@ mod tests {
map.in_i = usize::MAX - 13;
map.out_i = usize::MAX - 13;
- assert!(map.eq((0..100).into_iter().map(|i| 2 * i)));
+ assert!(map.eq((0..100).map(|i| 2 * i)));
}
#[test]
@@ -510,16 +500,14 @@ mod tests {
let counter = Arc::new(Mutex::new(0));
let count = counter.clone();
- let mut iter = (0..)
- .into_iter()
- .map_parallel_limit(threads, buffer_size, move |i| {
- if i < consume {
- std::thread::sleep(Duration::from_millis(100));
- }
- let mut counter = counter.lock().unwrap();
- *counter += 1;
- 2 * i
- });
+ let mut iter = (0..).map_parallel_limit(threads, buffer_size, move |i| {
+ if i < consume {
+ std::thread::sleep(Duration::from_millis(100));
+ }
+ let mut counter = counter.lock().unwrap();
+ *counter += 1;
+ 2 * i
+ });
for _ in 0..consume {
iter.next();
}
Generated by cgit. See skreutz.com for my tech blog and contact information.