mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Rename field in OnceWith from gen to make
This commit is contained in:
@@ -58,8 +58,8 @@
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "iter_once_with", since = "1.43.0")]
|
||||
pub fn once_with<A, F: FnOnce() -> A>(gen: F) -> OnceWith<F> {
|
||||
OnceWith { gen: Some(gen) }
|
||||
pub fn once_with<A, F: FnOnce() -> A>(make: F) -> OnceWith<F> {
|
||||
OnceWith { make: Some(make) }
|
||||
}
|
||||
|
||||
/// An iterator that yields a single element of type `A` by
|
||||
@@ -70,13 +70,13 @@ pub fn once_with<A, F: FnOnce() -> A>(gen: F) -> OnceWith<F> {
|
||||
#[derive(Clone)]
|
||||
#[stable(feature = "iter_once_with", since = "1.43.0")]
|
||||
pub struct OnceWith<F> {
|
||||
gen: Option<F>,
|
||||
make: Option<F>,
|
||||
}
|
||||
|
||||
#[stable(feature = "iter_once_with_debug", since = "1.68.0")]
|
||||
impl<F> fmt::Debug for OnceWith<F> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
if self.gen.is_some() {
|
||||
if self.make.is_some() {
|
||||
f.write_str("OnceWith(Some(_))")
|
||||
} else {
|
||||
f.write_str("OnceWith(None)")
|
||||
@@ -90,13 +90,13 @@ impl<A, F: FnOnce() -> A> Iterator for OnceWith<F> {
|
||||
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<A> {
|
||||
let f = self.gen.take()?;
|
||||
let f = self.make.take()?;
|
||||
Some(f())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
self.gen.iter().size_hint()
|
||||
self.make.iter().size_hint()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ fn next_back(&mut self) -> Option<A> {
|
||||
#[stable(feature = "iter_once_with", since = "1.43.0")]
|
||||
impl<A, F: FnOnce() -> A> ExactSizeIterator for OnceWith<F> {
|
||||
fn len(&self) -> usize {
|
||||
self.gen.iter().len()
|
||||
self.make.iter().len()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user