aboutsummaryrefslogtreecommitdiff
path: root/src/sources.rs
diff options
context:
space:
mode:
authorJoel Galenson <jgalenson@google.com>2021-04-06 16:54:27 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-04-06 16:54:27 +0000
commit16514b8f2782005df002eb2e0e0cb0e957b6e694 (patch)
tree70e883bc01ba2b4d8dd07e0347be18a2fbbd2c18 /src/sources.rs
parentb9502874a5f4caa02c9ffb0613e13e18cdbf1258 (diff)
parente7475af42409e513e29e78847cebaa1dabeb9765 (diff)
downloaditertools-16514b8f2782005df002eb2e0e0cb0e957b6e694.tar.gz
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/itertools/+/1662678 Change-Id: Ic90558e20c754158850e38f901c0cefd7a9bc6f3
Diffstat (limited to 'src/sources.rs')
-rw-r--r--src/sources.rs33
1 files changed, 13 insertions, 20 deletions
diff --git a/src/sources.rs b/src/sources.rs
index 17d9ff9..5bb6afe 100644
--- a/src/sources.rs
+++ b/src/sources.rs
@@ -7,7 +7,7 @@ use std::mem;
/// See [`repeat_call`](../fn.repeat_call.html) for more information.
#[derive(Clone)]
-#[deprecated(note="Use std repeat_with() instead", since="0.8")]
+#[deprecated(note="Use std repeat_with() instead", since="0.8.0")]
pub struct RepeatCall<F> {
f: F,
}
@@ -39,7 +39,7 @@ impl<F> fmt::Debug for RepeatCall<F>
/// vec![1, 1, 1, 1, 1]
/// );
/// ```
-#[deprecated(note="Use std repeat_with() instead", since="0.8")]
+#[deprecated(note="Use std repeat_with() instead", since="0.8.0")]
pub fn repeat_call<F, A>(function: F) -> RepeatCall<F>
where F: FnMut() -> A
{
@@ -52,7 +52,7 @@ impl<A, F> Iterator for RepeatCall<F>
type Item = A;
#[inline]
- fn next(&mut self) -> Option<A> {
+ fn next(&mut self) -> Option<Self::Item> {
Some((self.f)())
}
@@ -76,22 +76,21 @@ impl<A, F> Iterator for RepeatCall<F>
///
/// use itertools::unfold;
///
-/// let (mut x1, mut x2) = (1u32, 1u32);
-/// let mut fibonacci = unfold((), move |_| {
+/// let mut fibonacci = unfold((1u32, 1u32), |(x1, x2)| {
/// // Attempt to get the next Fibonacci number
-/// let next = x1.saturating_add(x2);
+/// let next = x1.saturating_add(*x2);
///
/// // Shift left: ret <- x1 <- x2 <- next
-/// let ret = x1;
-/// x1 = x2;
-/// x2 = next;
+/// let ret = *x1;
+/// *x1 = *x2;
+/// *x2 = next;
///
/// // If addition has saturated at the maximum, we are finished
-/// if ret == x1 && ret > 1 {
-/// return None;
+/// if ret == *x1 && ret > 1 {
+/// None
+/// } else {
+/// Some(ret)
/// }
-///
-/// Some(ret)
/// });
///
/// itertools::assert_equal(fibonacci.by_ref().take(8),
@@ -128,15 +127,9 @@ impl<A, St, F> Iterator for Unfold<St, F>
type Item = A;
#[inline]
- fn next(&mut self) -> Option<A> {
+ fn next(&mut self) -> Option<Self::Item> {
(self.f)(&mut self.state)
}
-
- #[inline]
- fn size_hint(&self) -> (usize, Option<usize>) {
- // no possible known bounds at this point
- (0, None)
- }
}
/// An iterator that infinitely applies function to value and yields results.