Auto merge of #51200 - tmccombs:stable-iter-repeat-with, r=Centril,kennytm
Stabilize iterator_repeat_with Fixes #48169
This commit is contained in:
commit
c5a129e809
|
@ -333,7 +333,7 @@ pub use self::range::Step;
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub use self::sources::{Repeat, repeat};
|
pub use self::sources::{Repeat, repeat};
|
||||||
#[unstable(feature = "iterator_repeat_with", issue = "48169")]
|
#[stable(feature = "iterator_repeat_with", since = "1.28.0")]
|
||||||
pub use self::sources::{RepeatWith, repeat_with};
|
pub use self::sources::{RepeatWith, repeat_with};
|
||||||
#[stable(feature = "iter_empty", since = "1.2.0")]
|
#[stable(feature = "iter_empty", since = "1.2.0")]
|
||||||
pub use self::sources::{Empty, empty};
|
pub use self::sources::{Empty, empty};
|
||||||
|
|
|
@ -113,12 +113,12 @@ pub fn repeat<T: Clone>(elt: T) -> Repeat<T> {
|
||||||
///
|
///
|
||||||
/// [`repeat_with`]: fn.repeat_with.html
|
/// [`repeat_with`]: fn.repeat_with.html
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
#[unstable(feature = "iterator_repeat_with", issue = "48169")]
|
#[stable(feature = "iterator_repeat_with", since = "1.28.0")]
|
||||||
pub struct RepeatWith<F> {
|
pub struct RepeatWith<F> {
|
||||||
repeater: F
|
repeater: F
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "iterator_repeat_with", issue = "48169")]
|
#[stable(feature = "iterator_repeat_with", since = "1.28.0")]
|
||||||
impl<A, F: FnMut() -> A> Iterator for RepeatWith<F> {
|
impl<A, F: FnMut() -> A> Iterator for RepeatWith<F> {
|
||||||
type Item = A;
|
type Item = A;
|
||||||
|
|
||||||
|
@ -129,13 +129,7 @@ impl<A, F: FnMut() -> A> Iterator for RepeatWith<F> {
|
||||||
fn size_hint(&self) -> (usize, Option<usize>) { (usize::MAX, None) }
|
fn size_hint(&self) -> (usize, Option<usize>) { (usize::MAX, None) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "iterator_repeat_with", issue = "48169")]
|
#[stable(feature = "iterator_repeat_with", since = "1.28.0")]
|
||||||
impl<A, F: FnMut() -> A> DoubleEndedIterator for RepeatWith<F> {
|
|
||||||
#[inline]
|
|
||||||
fn next_back(&mut self) -> Option<A> { self.next() }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[unstable(feature = "iterator_repeat_with", issue = "48169")]
|
|
||||||
impl<A, F: FnMut() -> A> FusedIterator for RepeatWith<F> {}
|
impl<A, F: FnMut() -> A> FusedIterator for RepeatWith<F> {}
|
||||||
|
|
||||||
#[unstable(feature = "trusted_len", issue = "37572")]
|
#[unstable(feature = "trusted_len", issue = "37572")]
|
||||||
|
@ -158,19 +152,15 @@ unsafe impl<A, F: FnMut() -> A> TrustedLen for RepeatWith<F> {}
|
||||||
///
|
///
|
||||||
/// [`repeat`]: fn.repeat.html
|
/// [`repeat`]: fn.repeat.html
|
||||||
///
|
///
|
||||||
/// An iterator produced by `repeat_with()` is a `DoubleEndedIterator`.
|
/// An iterator produced by `repeat_with()` is not a `DoubleEndedIterator`.
|
||||||
/// It is important to note that reversing `repeat_with(f)` will produce
|
/// If you need `repeat_with()` to return a `DoubleEndedIterator`,
|
||||||
/// the exact same sequence as the non-reversed iterator. In other words,
|
/// please open a GitHub issue explaining your use case.
|
||||||
/// `repeat_with(f).rev().collect::<Vec<_>>()` is equivalent to
|
|
||||||
/// `repeat_with(f).collect::<Vec<_>>()`.
|
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// Basic usage:
|
/// Basic usage:
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(iterator_repeat_with)]
|
|
||||||
///
|
|
||||||
/// use std::iter;
|
/// use std::iter;
|
||||||
///
|
///
|
||||||
/// // let's assume we have some value of a type that is not `Clone`
|
/// // let's assume we have some value of a type that is not `Clone`
|
||||||
|
@ -191,8 +181,6 @@ unsafe impl<A, F: FnMut() -> A> TrustedLen for RepeatWith<F> {}
|
||||||
/// Using mutation and going finite:
|
/// Using mutation and going finite:
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// #![feature(iterator_repeat_with)]
|
|
||||||
///
|
|
||||||
/// use std::iter;
|
/// use std::iter;
|
||||||
///
|
///
|
||||||
/// // From the zeroth to the third power of two:
|
/// // From the zeroth to the third power of two:
|
||||||
|
@ -209,7 +197,7 @@ unsafe impl<A, F: FnMut() -> A> TrustedLen for RepeatWith<F> {}
|
||||||
/// assert_eq!(None, pow2.next());
|
/// assert_eq!(None, pow2.next());
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "iterator_repeat_with", issue = "48169")]
|
#[stable(feature = "iterator_repeat_with", since = "1.28.0")]
|
||||||
pub fn repeat_with<A, F: FnMut() -> A>(repeater: F) -> RepeatWith<F> {
|
pub fn repeat_with<A, F: FnMut() -> A>(repeater: F) -> RepeatWith<F> {
|
||||||
RepeatWith { repeater }
|
RepeatWith { repeater }
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,6 @@
|
||||||
#![feature(fundamental)]
|
#![feature(fundamental)]
|
||||||
#![feature(intrinsics)]
|
#![feature(intrinsics)]
|
||||||
#![feature(iterator_flatten)]
|
#![feature(iterator_flatten)]
|
||||||
#![feature(iterator_repeat_with)]
|
|
||||||
#![feature(lang_items)]
|
#![feature(lang_items)]
|
||||||
#![feature(link_llvm_intrinsics)]
|
#![feature(link_llvm_intrinsics)]
|
||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
|
|
|
@ -1722,18 +1722,6 @@ fn test_repeat_with() {
|
||||||
assert_eq!(repeat_with(|| NotClone(42)).size_hint(), (usize::MAX, None));
|
assert_eq!(repeat_with(|| NotClone(42)).size_hint(), (usize::MAX, None));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_repeat_with_rev() {
|
|
||||||
let mut curr = 1;
|
|
||||||
let mut pow2 = repeat_with(|| { let tmp = curr; curr *= 2; tmp })
|
|
||||||
.rev().take(4);
|
|
||||||
assert_eq!(pow2.next(), Some(1));
|
|
||||||
assert_eq!(pow2.next(), Some(2));
|
|
||||||
assert_eq!(pow2.next(), Some(4));
|
|
||||||
assert_eq!(pow2.next(), Some(8));
|
|
||||||
assert_eq!(pow2.next(), None);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_repeat_with_take() {
|
fn test_repeat_with_take() {
|
||||||
let mut it = repeat_with(|| 42).take(3);
|
let mut it = repeat_with(|| 42).take(3);
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
#![feature(fmt_internals)]
|
#![feature(fmt_internals)]
|
||||||
#![feature(hashmap_internals)]
|
#![feature(hashmap_internals)]
|
||||||
#![feature(iterator_flatten)]
|
#![feature(iterator_flatten)]
|
||||||
#![feature(iterator_repeat_with)]
|
|
||||||
#![feature(pattern)]
|
#![feature(pattern)]
|
||||||
#![feature(range_is_empty)]
|
#![feature(range_is_empty)]
|
||||||
#![feature(raw)]
|
#![feature(raw)]
|
||||||
|
|
Loading…
Reference in New Issue