Rename field in OnceWith from gen to make
This commit is contained in:
parent
9c486a74da
commit
04bbc8340a
1 changed files with 7 additions and 7 deletions
|
|
@ -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
|
||||
|
|
@ -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 @@ 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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue