Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't derive Debug for OnceWith & RepeatWith #104163

Merged
merged 1 commit into from Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion library/core/src/iter/sources/once_with.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::fmt;
use crate::iter::{FusedIterator, TrustedLen};

/// Creates an iterator that lazily generates a value exactly once by invoking
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion library/core/src/iter/sources/repeat_with.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::fmt;
use crate::iter::{FusedIterator, TrustedLen};
use crate::ops::Try;

Expand Down Expand Up @@ -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;
Expand Down