Skip to content

Commit

Permalink
Rename field in OnceWith from gen to make
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Feb 9, 2025
1 parent 9c486a7 commit 04bbc83
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions library/core/src/iter/sources/once_with.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ use crate::iter::{FusedIterator, TrustedLen};
/// ```
#[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
Expand All @@ -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)")
Expand All @@ -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()
}
}

Expand All @@ -110,7 +110,7 @@ impl<A, F: FnOnce() -> A> DoubleEndedIterator for OnceWith<F> {
#[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()
}
}

Expand Down

0 comments on commit 04bbc83

Please sign in to comment.