Rollup merge of #104163 - H4x5:once-repeat-with-debug, r=dtolnay

Don't derive Debug for `OnceWith` & `RepeatWith`

Closures don't impl Debug, so the derived impl is kinda useless. The behavior of not debug-printing closures is consistent with the rest of the iterator adapters/sources.
This commit is contained in:
Michael Goulet 2023-01-08 19:57:52 -08:00 committed by GitHub
commit db87e276c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View File

@ -1,3 +1,4 @@
use crate::fmt;
use crate::iter::{FusedIterator, TrustedLen};
/// Creates an iterator that lazily generates a value exactly once by invoking
@ -66,12 +67,23 @@ pub fn once_with<A, F: FnOnce() -> A>(gen: F) -> OnceWith<F> {
///
/// This `struct` is created by the [`once_with()`] function.
/// See its documentation for more.
#[derive(Clone, Debug)]
#[derive(Clone)]
#[stable(feature = "iter_once_with", since = "1.43.0")]
pub struct OnceWith<F> {
gen: Option<F>,
}
#[stable(feature = "iter_once_with_debug", since = "CURRENT_RUSTC_VERSION")]
impl<F> fmt::Debug for OnceWith<F> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.gen.is_some() {
f.write_str("OnceWith(Some(_))")
} else {
f.write_str("OnceWith(None)")
}
}
}
#[stable(feature = "iter_once_with", since = "1.43.0")]
impl<A, F: FnOnce() -> A> Iterator for OnceWith<F> {
type Item = A;

View File

@ -1,3 +1,4 @@
use crate::fmt;
use crate::iter::{FusedIterator, TrustedLen};
use crate::ops::Try;
@ -71,12 +72,19 @@ pub fn repeat_with<A, F: FnMut() -> A>(repeater: F) -> RepeatWith<F> {
///
/// This `struct` is created by the [`repeat_with()`] function.
/// See its documentation for more.
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone)]
#[stable(feature = "iterator_repeat_with", since = "1.28.0")]
pub struct RepeatWith<F> {
repeater: F,
}
#[stable(feature = "iterator_repeat_with_debug", since = "CURRENT_RUSTC_VERSION")]
impl<F> fmt::Debug for RepeatWith<F> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("RepeatWith").finish_non_exhaustive()
}
}
#[stable(feature = "iterator_repeat_with", since = "1.28.0")]
impl<A, F: FnMut() -> A> Iterator for RepeatWith<F> {
type Item = A;