Stabilize core::iter::once_with()

This commit is contained in:
Yuki Okushi 2020-02-04 00:47:04 +09:00
parent c58e09f138
commit 7e2d7e0bbc
4 changed files with 8 additions and 14 deletions

View File

@ -327,7 +327,7 @@ pub use self::sources::{empty, Empty};
pub use self::sources::{from_fn, FromFn}; pub use self::sources::{from_fn, FromFn};
#[stable(feature = "iter_once", since = "1.2.0")] #[stable(feature = "iter_once", since = "1.2.0")]
pub use self::sources::{once, Once}; pub use self::sources::{once, Once};
#[unstable(feature = "iter_once_with", issue = "57581")] #[stable(feature = "iter_once_with", since = "1.43.0")]
pub use self::sources::{once_with, OnceWith}; pub use self::sources::{once_with, OnceWith};
#[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};

View File

@ -399,12 +399,12 @@ pub fn once<T>(value: T) -> Once<T> {
/// ///
/// [`once_with`]: fn.once_with.html /// [`once_with`]: fn.once_with.html
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
#[unstable(feature = "iter_once_with", issue = "57581")] #[stable(feature = "iter_once_with", since = "1.43.0")]
pub struct OnceWith<F> { pub struct OnceWith<F> {
gen: Option<F>, gen: Option<F>,
} }
#[unstable(feature = "iter_once_with", issue = "57581")] #[stable(feature = "iter_once_with", since = "1.43.0")]
impl<A, F: FnOnce() -> A> Iterator for OnceWith<F> { impl<A, F: FnOnce() -> A> Iterator for OnceWith<F> {
type Item = A; type Item = A;
@ -420,24 +420,24 @@ impl<A, F: FnOnce() -> A> Iterator for OnceWith<F> {
} }
} }
#[unstable(feature = "iter_once_with", issue = "57581")] #[stable(feature = "iter_once_with", since = "1.43.0")]
impl<A, F: FnOnce() -> A> DoubleEndedIterator for OnceWith<F> { impl<A, F: FnOnce() -> A> DoubleEndedIterator for OnceWith<F> {
fn next_back(&mut self) -> Option<A> { fn next_back(&mut self) -> Option<A> {
self.next() self.next()
} }
} }
#[unstable(feature = "iter_once_with", issue = "57581")] #[stable(feature = "iter_once_with", since = "1.43.0")]
impl<A, F: FnOnce() -> A> ExactSizeIterator for OnceWith<F> { impl<A, F: FnOnce() -> A> ExactSizeIterator for OnceWith<F> {
fn len(&self) -> usize { fn len(&self) -> usize {
self.gen.iter().len() self.gen.iter().len()
} }
} }
#[unstable(feature = "iter_once_with", issue = "57581")] #[stable(feature = "iter_once_with", since = "1.43.0")]
impl<A, F: FnOnce() -> A> FusedIterator for OnceWith<F> {} impl<A, F: FnOnce() -> A> FusedIterator for OnceWith<F> {}
#[unstable(feature = "iter_once_with", issue = "57581")] #[stable(feature = "iter_once_with", since = "1.43.0")]
unsafe impl<A, F: FnOnce() -> A> TrustedLen for OnceWith<F> {} unsafe impl<A, F: FnOnce() -> A> TrustedLen for OnceWith<F> {}
/// Creates an iterator that lazily generates a value exactly once by invoking /// Creates an iterator that lazily generates a value exactly once by invoking
@ -458,8 +458,6 @@ unsafe impl<A, F: FnOnce() -> A> TrustedLen for OnceWith<F> {}
/// Basic usage: /// Basic usage:
/// ///
/// ``` /// ```
/// #![feature(iter_once_with)]
///
/// use std::iter; /// use std::iter;
/// ///
/// // one is the loneliest number /// // one is the loneliest number
@ -476,8 +474,6 @@ unsafe impl<A, F: FnOnce() -> A> TrustedLen for OnceWith<F> {}
/// `.foorc`: /// `.foorc`:
/// ///
/// ```no_run /// ```no_run
/// #![feature(iter_once_with)]
///
/// use std::iter; /// use std::iter;
/// use std::fs; /// use std::fs;
/// use std::path::PathBuf; /// use std::path::PathBuf;
@ -500,7 +496,7 @@ unsafe impl<A, F: FnOnce() -> A> TrustedLen for OnceWith<F> {}
/// } /// }
/// ``` /// ```
#[inline] #[inline]
#[unstable(feature = "iter_once_with", issue = "57581")] #[stable(feature = "iter_once_with", since = "1.43.0")]
pub fn once_with<A, F: FnOnce() -> A>(gen: F) -> OnceWith<F> { pub fn once_with<A, F: FnOnce() -> A>(gen: F) -> OnceWith<F> {
OnceWith { gen: Some(gen) } OnceWith { gen: Some(gen) }
} }

View File

@ -87,7 +87,6 @@
#![feature(intrinsics)] #![feature(intrinsics)]
#![feature(try_find)] #![feature(try_find)]
#![feature(is_sorted)] #![feature(is_sorted)]
#![feature(iter_once_with)]
#![feature(lang_items)] #![feature(lang_items)]
#![feature(link_llvm_intrinsics)] #![feature(link_llvm_intrinsics)]
#![feature(never_type)] #![feature(never_type)]

View File

@ -13,7 +13,6 @@
#![feature(hashmap_internals)] #![feature(hashmap_internals)]
#![feature(try_find)] #![feature(try_find)]
#![feature(is_sorted)] #![feature(is_sorted)]
#![feature(iter_once_with)]
#![feature(pattern)] #![feature(pattern)]
#![feature(range_is_empty)] #![feature(range_is_empty)]
#![feature(raw)] #![feature(raw)]