Skip to content

Commit

Permalink
Stabilize iter::successors
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Feb 19, 2019
1 parent 4d66b7b commit 95d2795
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/libcore/iter/mod.rs
Expand Up @@ -327,7 +327,9 @@ pub use self::sources::{Once, once};
#[unstable(feature = "iter_once_with", issue = "57581")]
pub use self::sources::{OnceWith, once_with};
#[unstable(feature = "iter_unfold", issue = "55977")]
pub use self::sources::{FromFn, from_fn, Successors, successors};
pub use self::sources::{FromFn, from_fn};
#[stable(feature = "iter_successors", since = "1.34.0")]
pub use self::sources::{Successors, successors};

#[stable(feature = "rust1", since = "1.0.0")]
pub use self::traits::{FromIterator, IntoIterator, DoubleEndedIterator, Extend};
Expand Down
11 changes: 5 additions & 6 deletions src/libcore/iter/sources.rs
Expand Up @@ -572,13 +572,12 @@ impl<F> fmt::Debug for FromFn<F> {
/// and calls the given `FnMut(&T) -> Option<T>` closure to compute each item’s successor.
///
/// ```
/// #![feature(iter_unfold)]
/// use std::iter::successors;
///
/// let powers_of_10 = successors(Some(1_u16), |n| n.checked_mul(10));
/// assert_eq!(powers_of_10.collect::<Vec<_>>(), &[1, 10, 100, 1_000, 10_000]);
/// ```
#[unstable(feature = "iter_unfold", issue = "55977")]
#[stable(feature = "iter_successors", since = "1.34.0")]
pub fn successors<T, F>(first: Option<T>, succ: F) -> Successors<T, F>
where F: FnMut(&T) -> Option<T>
{
Expand All @@ -598,13 +597,13 @@ pub fn successors<T, F>(first: Option<T>, succ: F) -> Successors<T, F>
///
/// [`successors`]: fn.successors.html
#[derive(Clone)]
#[unstable(feature = "iter_unfold", issue = "55977")]
#[stable(feature = "iter_successors", since = "1.34.0")]
pub struct Successors<T, F> {
next: Option<T>,
succ: F,
}

#[unstable(feature = "iter_unfold", issue = "55977")]
#[stable(feature = "iter_successors", since = "1.34.0")]
impl<T, F> Iterator for Successors<T, F>
where F: FnMut(&T) -> Option<T>
{
Expand All @@ -628,12 +627,12 @@ impl<T, F> Iterator for Successors<T, F>
}
}

#[unstable(feature = "iter_unfold", issue = "55977")]
#[stable(feature = "iter_successors", since = "1.34.0")]
impl<T, F> FusedIterator for Successors<T, F>
where F: FnMut(&T) -> Option<T>
{}

#[unstable(feature = "iter_unfold", issue = "55977")]
#[stable(feature = "iter_successors", since = "1.34.0")]
impl<T: fmt::Debug, F> fmt::Debug for Successors<T, F> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Successors")
Expand Down

0 comments on commit 95d2795

Please sign in to comment.