Trait otter_base::prelude::Debug 1.0.0[−][src]
Expand description
?
formatting.
Debug
should format the output in a programmer-facing, debugging context.
Generally speaking, you should just derive
a Debug
implementation.
When used with the alternate format specifier #?
, the output is pretty-printed.
For more information on formatters, see the module-level documentation.
This trait can be used with #[derive]
if all fields implement Debug
. When
derive
d for structs, it will use the name of the struct
, then {
, then a
comma-separated list of each field’s name and Debug
value, then }
. For
enum
s, it will use the name of the variant and, if applicable, (
, then the
Debug
values of the fields, then )
.
Stability
Derived Debug
formats are not stable, and so may change with future Rust
versions. Additionally, Debug
implementations of types provided by the
standard library (libstd
, libcore
, liballoc
, etc.) are not stable, and
may also change with future Rust versions.
Examples
Deriving an implementation:
#[derive(Debug)] struct Point { x: i32, y: i32, } let origin = Point { x: 0, y: 0 }; assert_eq!(format!("The origin is: {:?}", origin), "The origin is: Point { x: 0, y: 0 }");
Manually implementing:
use std::fmt; struct Point { x: i32, y: i32, } impl fmt::Debug for Point { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Point") .field("x", &self.x) .field("y", &self.y) .finish() } } let origin = Point { x: 0, y: 0 }; assert_eq!(format!("The origin is: {:?}", origin), "The origin is: Point { x: 0, y: 0 }");
There are a number of helper methods on the Formatter
struct to help you with manual
implementations, such as debug_struct
.
Debug
implementations using either derive
or the debug builder API
on Formatter
support pretty-printing using the alternate flag: {:#?}
.
Pretty-printing with #?
:
#[derive(Debug)] struct Point { x: i32, y: i32, } let origin = Point { x: 0, y: 0 }; assert_eq!(format!("The origin is: {:#?}", origin), "The origin is: Point { x: 0, y: 0, }");
Required methods
Formats the value using the given formatter.
Examples
use std::fmt; struct Position { longitude: f32, latitude: f32, } impl fmt::Debug for Position { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("") .field(&self.longitude) .field(&self.latitude) .finish() } } let position = Position { longitude: 1.987, latitude: 2.983 }; assert_eq!(format!("{:?}", position), "(1.987, 2.983)"); assert_eq!(format!("{:#?}", position), "( 1.987, 2.983, )");
Implementations on Foreign Types
1.16.0[src]impl<'_, T, S> Debug for Intersection<'_, T, S> where
T: Debug + Eq + Hash,
S: BuildHasher,
impl<'_, T, S> Debug for Intersection<'_, T, S> where
T: Debug + Eq + Hash,
S: BuildHasher,
1.16.0[src]impl<'_, T, S> Debug for SymmetricDifference<'_, T, S> where
T: Debug + Eq + Hash,
S: BuildHasher,
impl<'_, T, S> Debug for SymmetricDifference<'_, T, S> where
T: Debug + Eq + Hash,
S: BuildHasher,
1.16.0[src]impl<'_, T, S> Debug for Difference<'_, T, S> where
T: Debug + Eq + Hash,
S: BuildHasher,
impl<'_, T, S> Debug for Difference<'_, T, S> where
T: Debug + Eq + Hash,
S: BuildHasher,
impl<T> Debug for TupleBuffer<T> where
T: Debug + HomogeneousTuple,
<T as TupleCollect>::Buffer: Debug,
impl<T> Debug for TupleBuffer<T> where
T: Debug + HomogeneousTuple,
<T as TupleCollect>::Buffer: Debug,
impl<I, T> Debug for TupleWindows<I, T> where
T: Debug + HomogeneousTuple,
I: Debug + Iterator<Item = <T as TupleCollect>::Item>,
impl<I, T> Debug for TupleWindows<I, T> where
T: Debug + HomogeneousTuple,
I: Debug + Iterator<Item = <T as TupleCollect>::Item>,
impl<I, T, E> Debug for FlattenOk<I, T, E> where
T: IntoIterator,
I: Iterator<Item = Result<T, E>> + Debug,
<T as IntoIterator>::IntoIter: Debug,
impl<I, T, E> Debug for FlattenOk<I, T, E> where
T: IntoIterator,
I: Iterator<Item = Result<T, E>> + Debug,
<T as IntoIterator>::IntoIter: Debug,
impl<FORMAT, STRICTNESS> Debug for TimestampMicroSeconds<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for TimestampMicroSeconds<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for DurationMilliSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for DurationMilliSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for TimestampSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for TimestampSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for TimestampMicroSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for TimestampMicroSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for DurationNanoSeconds<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for DurationNanoSeconds<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for TimestampSeconds<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for TimestampSeconds<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for DurationMicroSeconds<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for DurationMicroSeconds<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for DurationMilliSeconds<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for DurationMilliSeconds<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for DurationSeconds<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for DurationSeconds<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for TimestampNanoSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for TimestampNanoSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for TimestampMilliSeconds<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for TimestampMilliSeconds<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for TimestampNanoSeconds<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for TimestampNanoSeconds<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for DurationSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for DurationSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for DurationNanoSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for DurationNanoSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for TimestampMilliSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for TimestampMilliSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for DurationMicroSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
impl<FORMAT, STRICTNESS> Debug for DurationMicroSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Debug + Format,
STRICTNESS: Debug + Strictness,
Implementors
impl<'a, P> Debug for MatchIndices<'a, P> where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: Debug,
impl<'a, P> Debug for Matches<'a, P> where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: Debug,
impl<'a, P> Debug for RMatchIndices<'a, P> where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: Debug,
impl<'a, P> Debug for RMatches<'a, P> where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: Debug,
impl<'a, P> Debug for otter_base::prelude::str::RSplit<'a, P> where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: Debug,
impl<'a, P> Debug for otter_base::prelude::str::RSplitN<'a, P> where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: Debug,
impl<'a, P> Debug for RSplitTerminator<'a, P> where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: Debug,
impl<'a, P> Debug for otter_base::prelude::str::Split<'a, P> where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: Debug,
impl<'a, P> Debug for otter_base::prelude::str::SplitInclusive<'a, P> where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: Debug,
impl<'a, P> Debug for otter_base::prelude::str::SplitN<'a, P> where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: Debug,
impl<'a, P> Debug for SplitTerminator<'a, P> where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: Debug,
impl<I> Debug for Intersperse<I> where
I: Debug + Iterator,
<I as Iterator>::Item: Clone,
<I as Iterator>::Item: Debug,
impl<I, G> Debug for otter_base::prelude::iter::IntersperseWith<I, G> where
I: Iterator + Debug,
G: Debug,
<I as Iterator>::Item: Debug,
impl<I, U> Debug for Flatten<I> where
I: Debug + Iterator,
U: Debug + Iterator,
<I as Iterator>::Item: IntoIterator,
<<I as Iterator>::Item as IntoIterator>::IntoIter == U,
<<I as Iterator>::Item as IntoIterator>::Item == <U as Iterator>::Item,
impl<I, U, F> Debug for FlatMap<I, U, F> where
I: Debug,
U: IntoIterator,
<U as IntoIterator>::IntoIter: Debug,