]> git.lizzy.rs Git - rust.git/commitdiff
Don't derive Debug for `OnceWith` & `RepeatWith`
authorSky <sky@h4x5.dev>
Sat, 7 Jan 2023 19:16:59 +0000 (14:16 -0500)
committerSky <sky@h4x5.dev>
Sat, 7 Jan 2023 19:28:44 +0000 (14:28 -0500)
library/core/src/iter/sources/once_with.rs
library/core/src/iter/sources/repeat_with.rs

index d79f85c2559fedf5f3e2f0641f8ca69a71c57edd..080ae27a30fcf976dd3e483e8fe6b14d8f3f65e4 100644 (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;
index ab2d0472b4701c205e0426582b5587c42baabeb9..20420a3ad8e02a83df814e758b5cc9e8481f83a2 100644 (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;