pub struct DebugList<'a, 'b>where
'b: 'a,{ /* private fields */ }
Expand description
A struct to help with fmt::Debug
implementations.
This is useful when you wish to output a formatted list of items as a part
of your Debug::fmt
implementation.
This can be constructed by the Formatter::debug_list
method.
Examples
use std::fmt;
struct Foo(Vec<i32>);
impl fmt::Debug for Foo {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_list().entries(self.0.iter()).finish()
}
}
assert_eq!(
format!("{:?}", Foo(vec![10, 11])),
"[10, 11]",
);
Implementations§
source§impl<'a, 'b> DebugList<'a, 'b>where
'b: 'a,
impl<'a, 'b> DebugList<'a, 'b>where 'b: 'a,
sourcepub fn entry(&mut self, entry: &dyn Debug) -> &mut DebugList<'a, 'b>
Available on crate feature mem
only.
pub fn entry(&mut self, entry: &dyn Debug) -> &mut DebugList<'a, 'b>
mem
only.Adds a new entry to the list output.
Examples
use std::fmt;
struct Foo(Vec<i32>, Vec<u32>);
impl fmt::Debug for Foo {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_list()
.entry(&self.0) // We add the first "entry".
.entry(&self.1) // We add the second "entry".
.finish()
}
}
assert_eq!(
format!("{:?}", Foo(vec![10, 11], vec![12, 13])),
"[[10, 11], [12, 13]]",
);
sourcepub fn entry_with<F>(&mut self, entry_fmt: F) -> &mut DebugList<'a, 'b>where
F: FnOnce(&mut Formatter<'_>) -> Result<(), Error>,
🔬This is a nightly-only experimental API. (debug_closure_helpers
)Available on crate feature mem
only.
pub fn entry_with<F>(&mut self, entry_fmt: F) -> &mut DebugList<'a, 'b>where F: FnOnce(&mut Formatter<'_>) -> Result<(), Error>,
debug_closure_helpers
)mem
only.Adds a new entry to the list output.
This method is equivalent to DebugList::entry
, but formats the
entry using a provided closure rather than by calling Debug::fmt
.
sourcepub fn entries<D, I>(&mut self, entries: I) -> &mut DebugList<'a, 'b>where
D: Debug,
I: IntoIterator<Item = D>,
Available on crate feature mem
only.
pub fn entries<D, I>(&mut self, entries: I) -> &mut DebugList<'a, 'b>where D: Debug, I: IntoIterator<Item = D>,
mem
only.Adds the contents of an iterator of entries to the list output.
Examples
use std::fmt;
struct Foo(Vec<i32>, Vec<u32>);
impl fmt::Debug for Foo {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_list()
.entries(self.0.iter())
.entries(self.1.iter())
.finish()
}
}
assert_eq!(
format!("{:?}", Foo(vec![10, 11], vec![12, 13])),
"[10, 11, 12, 13]",
);
sourcepub fn finish(&mut self) -> Result<(), Error>
Available on crate feature mem
only.
pub fn finish(&mut self) -> Result<(), Error>
mem
only.Finishes output and returns any error encountered.
Examples
use std::fmt;
struct Foo(Vec<i32>);
impl fmt::Debug for Foo {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_list()
.entries(self.0.iter())
.finish() // Ends the list formatting.
}
}
assert_eq!(
format!("{:?}", Foo(vec![10, 11])),
"[10, 11]",
);
Auto Trait Implementations§
impl<'a, 'b> !RefUnwindSafe for DebugList<'a, 'b>
impl<'a, 'b> !Send for DebugList<'a, 'b>
impl<'a, 'b> !Sync for DebugList<'a, 'b>
impl<'a, 'b> Unpin for DebugList<'a, 'b>
impl<'a, 'b> !UnwindSafe for DebugList<'a, 'b>
Blanket Implementations§
source§impl<T> Also for T
impl<T> Also for T
source§impl<T> AnyExt for Twhere
T: Any,
impl<T> AnyExt for Twhere T: Any,
source§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
Available on crate feature
any
only.Returns the type name of
self
. Read moresource§fn as_any_ref(&self) -> &dyn Anywhere
Self: Sized,
fn as_any_ref(&self) -> &dyn Anywhere Self: Sized,
Available on crate feature
any
only.source§fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere Self: Sized,
Available on crate feature
any
only.source§impl<T, Res> Apply<Res> for Twhere
T: ?Sized,
impl<T, Res> Apply<Res> for Twhere T: ?Sized,
source§fn apply<F: FnOnce(Self) -> Res>(self, f: F) -> Reswhere
Self: Sized,
fn apply<F: FnOnce(Self) -> Res>(self, f: F) -> Reswhere Self: Sized,
Available on crate feature
result
only.Apply a function which takes the parameter by value.
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where T: CheckedCast<Dst>,
Casts the value.
source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere Src: CheckedCast<Dst>,
source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
source§impl<T> Mem for Twhere
T: ?Sized,
impl<T> Mem for Twhere T: ?Sized,
source§const NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Available on crate feature
mem
only.Whether dropping values of this type matters.
source§fn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
Available on crate feature
mem
only.Returns
true
if dropping values of this type matters.source§fn mem_drop(self)where
Self: Sized,
fn mem_drop(self)where Self: Sized,
Available on crate feature
mem
only.Drops
self
by running its destructor.source§fn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where Self: Sized,
Available on crate feature
mem
only.Forgets about
self
without running its destructor.source§fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere Self: Sized,
Available on crate feature
mem
only.Replaces
self
with other, returning the previous value of self
.source§fn mem_take(&mut self) -> Selfwhere
Self: Default,
fn mem_take(&mut self) -> Selfwhere Self: Default,
Available on crate feature
mem
only.Replaces
self
with its default value, returning the previous value of self
.source§fn mem_swap(&mut self, other: &mut Self)where
Self: Sized,
fn mem_swap(&mut self, other: &mut Self)where Self: Sized,
Available on crate feature
mem
only.Swaps the value of
self
and other
without deinitializing either one.source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where T: OverflowingCast<Dst>,
Casts the value.
source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere Src: OverflowingCast<Dst>,
source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Casts the value.
source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere T: SaturatingCast<Dst>,
Casts the value.
source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere Src: SaturatingCast<Dst>,
source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
source§impl<T> Size for T
impl<T> Size for T
source§const BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Available on crate feature
mem
only.The alignment of this type in bytes.
source§const BYTE_SIZE: usize = _
const BYTE_SIZE: usize = _
Available on crate feature
mem
only.The size of this type in bytes.
source§const PTR_SIZE: usize = 4usize
const PTR_SIZE: usize = 4usize
Available on crate feature
mem
only.The size of a pointer in bytes, for the current platform.
source§fn byte_align(&self) -> usize
fn byte_align(&self) -> usize
Available on crate feature
mem
only.Returns the alignment of this type in bytes.
source§impl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
source§fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dstwhere T: UnwrappedCast<Dst>,
Casts the value.
source§impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere Src: UnwrappedCast<Dst>,
source§fn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
Casts the value.
source§impl<T> WrappingAs for T
impl<T> WrappingAs for T
source§fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dstwhere T: WrappingCast<Dst>,
Casts the value.
source§impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere Src: WrappingCast<Dst>,
source§fn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
Casts the value.