diff options
| author | David Tolnay <dtolnay@gmail.com> | 2025-03-15 11:19:56 -0700 |
|---|---|---|
| committer | David Tolnay <dtolnay@gmail.com> | 2025-05-05 19:46:46 -0700 |
| commit | c35914383a92d7504f3a71c390dc2ebd14bce695 (patch) | |
| tree | 98fd9c3031fa7499faca2bc2a5161a5ca9e4e19a /library/alloc/src/vec | |
| parent | cd55868a8db4b9394be64082a290f11b1e03b5d3 (diff) | |
Consistent trait bounds for ExtractIf Debug impls
Diffstat (limited to 'library/alloc/src/vec')
| -rw-r--r-- | library/alloc/src/vec/extract_if.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/library/alloc/src/vec/extract_if.rs b/library/alloc/src/vec/extract_if.rs index 8a591a87796..a456d3d9e60 100644 --- a/library/alloc/src/vec/extract_if.rs +++ b/library/alloc/src/vec/extract_if.rs @@ -1,5 +1,5 @@ use core::ops::{Range, RangeBounds}; -use core::{ptr, slice}; +use core::{fmt, ptr, slice}; use super::Vec; use crate::alloc::{Allocator, Global}; @@ -16,7 +16,6 @@ use crate::alloc::{Allocator, Global}; /// let iter: std::vec::ExtractIf<'_, _, _> = v.extract_if(.., |x| *x % 2 == 0); /// ``` #[stable(feature = "extract_if", since = "1.87.0")] -#[derive(Debug)] #[must_use = "iterators are lazy and do nothing unless consumed"] pub struct ExtractIf< 'a, @@ -108,3 +107,15 @@ impl<T, F, A: Allocator> Drop for ExtractIf<'_, T, F, A> { } } } + +#[stable(feature = "extract_if", since = "1.87.0")] +impl<T, F, A> fmt::Debug for ExtractIf<'_, T, F, A> +where + T: fmt::Debug, + A: Allocator, +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let peek = if self.idx < self.end { self.vec.get(self.idx) } else { None }; + f.debug_struct("ExtractIf").field("peek", &peek).finish_non_exhaustive() + } +} |
