Trait tract_hir::prelude::tract_data::internal::tract_smallvec::alloc::fmt::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
Implementors
impl<'_, K> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::hash_set::Drain<'_, K> where
K: Debug,
impl<'_, K> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::hash_set::Iter<'_, K> where
K: Debug,
impl<'_, K, V> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::btree_map::Entry<'_, K, V> where
K: Debug + Ord,
V: Debug,
impl<'_, K, V> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::hash_map::Entry<'_, K, V> where
K: Debug,
V: Debug,
impl<'_, K, V> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::btree_map::Iter<'_, K, V> where
K: Debug,
V: Debug,
impl<'_, K, V> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::btree_map::IterMut<'_, K, V> where
K: Debug,
V: Debug,
impl<'_, K, V> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::btree_map::Keys<'_, K, V> where
K: Debug,
impl<'_, K, V> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::btree_map::OccupiedEntry<'_, K, V> where
K: Debug + Ord,
V: Debug,
impl<'_, K, V> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::btree_map::OccupiedError<'_, K, V> where
K: Debug + Ord,
V: Debug,
impl<'_, K, V> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::btree_map::Range<'_, K, V> where
K: Debug,
V: Debug,
impl<'_, K, V> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::btree_map::VacantEntry<'_, K, V> where
K: Debug + Ord,
impl<'_, K, V> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::btree_map::Values<'_, K, V> where
V: Debug,
impl<'_, K, V> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::btree_map::ValuesMut<'_, K, V> where
V: Debug,
impl<'_, K, V> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::hash_map::Drain<'_, K, V> where
K: Debug,
V: Debug,
impl<'_, K, V> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::hash_map::Iter<'_, K, V> where
K: Debug,
V: Debug,
impl<'_, K, V> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::hash_map::IterMut<'_, K, V> where
K: Debug,
V: Debug,
impl<'_, K, V> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::hash_map::Keys<'_, K, V> where
K: Debug,
impl<'_, K, V> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::hash_map::OccupiedEntry<'_, K, V> where
K: Debug,
V: Debug,
impl<'_, K, V> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::hash_map::OccupiedError<'_, K, V> where
K: Debug,
V: Debug,
impl<'_, K, V> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::hash_map::VacantEntry<'_, K, V> where
K: Debug,
impl<'_, K, V> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::hash_map::Values<'_, K, V> where
V: Debug,
impl<'_, K, V> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::hash_map::ValuesMut<'_, K, V> where
V: Debug,
impl<'_, K, V, F> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::btree_map::DrainFilter<'_, K, V, F> where
K: Debug,
V: Debug,
F: FnMut(&K, &mut V) -> bool,
impl<'_, T> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::binary_heap::Iter<'_, T> where
T: Debug,
impl<'_, T> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::btree_set::Difference<'_, T> where
T: Debug,
impl<'_, T> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::btree_set::Intersection<'_, T> where
T: Debug,
impl<'_, T> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::btree_set::Iter<'_, T> where
T: Debug,
impl<'_, T> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::btree_set::SymmetricDifference<'_, T> where
T: Debug,
impl<'_, T> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::btree_set::Union<'_, T> where
T: Debug,
impl<'_, T> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::linked_list::Cursor<'_, T> where
T: Debug,
impl<'_, T> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::linked_list::Iter<'_, T> where
T: Debug,
impl<'_, T> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::linked_list::IterMut<'_, T> where
T: Debug,
impl<'_, T> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::vec_deque::Iter<'_, T> where
T: Debug,
impl<'_, T> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::vec_deque::IterMut<'_, T> where
T: Debug,
impl<'_, T> Debug for tract_hir::internal::tract_downcast_rs::__std::slice::Iter<'_, T> where
T: Debug,
impl<'_, T> Debug for tract_hir::internal::tract_downcast_rs::__std::slice::IterMut<'_, T> where
T: Debug,
impl<'_, T, A> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::vec_deque::Drain<'_, T, A> where
T: Debug,
A: Allocator,
impl<'_, T, A> Debug for tract_hir::internal::tract_downcast_rs::__std::vec::Drain<'_, T, A> where
T: Debug,
A: Allocator,
impl<'_, T, F> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::btree_set::DrainFilter<'_, T, F> where
T: Debug,
F: FnMut(&T) -> bool,
impl<'_, T, F> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::linked_list::DrainFilter<'_, T, F> where
F: FnMut(&mut T) -> bool,
T: Debug,
impl<'_, T, P> Debug for tract_hir::internal::tract_downcast_rs::__std::slice::RSplit<'_, T, P> where
P: FnMut(&T) -> bool,
T: Debug,
impl<'_, T, P> Debug for tract_hir::internal::tract_downcast_rs::__std::slice::RSplitN<'_, T, P> where
P: FnMut(&T) -> bool,
T: Debug,
impl<'_, T, P> Debug for tract_hir::internal::tract_downcast_rs::__std::slice::Split<'_, T, P> where
P: FnMut(&T) -> bool,
T: Debug,
impl<'_, T, P> Debug for tract_hir::internal::tract_downcast_rs::__std::slice::SplitN<'_, T, P> where
P: FnMut(&T) -> bool,
T: Debug,
impl<'_, T, S> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::hash_set::Difference<'_, T, S> where
T: Debug + Eq + Hash,
S: BuildHasher,
impl<'_, T, S> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::hash_set::Intersection<'_, T, S> where
T: Debug + Eq + Hash,
S: BuildHasher,
impl<'_, T, S> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::hash_set::SymmetricDifference<'_, T, S> where
T: Debug + Eq + Hash,
S: BuildHasher,
impl<'_, T, S> Debug for tract_hir::internal::tract_downcast_rs::__std::collections::hash_set::Union<'_, T, S> where
T: Debug + Eq + Hash,
S: BuildHasher,
impl<'a> Debug for tract_hir::internal::tract_downcast_rs::__std::os::unix::net::Incoming<'a>
impl<'a, A> Debug for tract_hir::internal::tract_downcast_rs::__std::option::Iter<'a, A> where
A: 'a + Debug,
impl<'a, A> Debug for tract_hir::internal::tract_downcast_rs::__std::option::IterMut<'a, A> where
A: 'a + Debug,
Format the array using Debug
and apply the formatting parameters used
to each element.
The array is shown in multiline style.