Skip to main content

Debug

Trait Debug 

1.6.0 · Source
pub trait Debug: PointeeSized {
    // Required method
    fn fmt(&self, f: &mut Formatter<'_>) -> Result;
}
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 derived 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 enums, 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 (std, core, alloc, 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.

Types that do not wish to use the standard suite of debug representations provided by the Formatter trait (debug_struct, debug_tuple, debug_list, debug_set, debug_map) can do something totally custom by manually writing an arbitrary representation to the Formatter.

impl fmt::Debug for Point {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "Point [{} {}]", self.x, self.y)
    }
}

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 };

let expected = "The origin is: Point {
    x: 0,
    y: 0,
}";
assert_eq!(format!("The origin is: {origin:#?}"), expected);

Required Methods§

1.0.0 · Source

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter.

§Errors

This function should return Err if, and only if, the provided Formatter returns Err. String formatting is considered an infallible operation; this function only returns a Result because writing to the underlying stream might fail and it must provide a way to propagate the fact that an error has occurred back up the stack.

§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,
)");

Implementors§

Source§

impl Debug for AsciiChar

1.0.0 · Source§

impl Debug for core::cmp::Ordering

1.34.0 · Source§

impl Debug for Infallible

1.64.0 · Source§

impl Debug for FromBytesWithNulError

1.16.0 · Source§

impl Debug for c_void

Source§

impl Debug for AtomicOrdering

1.0.0 · Source§

impl Debug for FpCategory

1.55.0 · Source§

impl Debug for IntErrorKind

Source§

impl Debug for SearchStep

1.0.0 · Source§

impl Debug for core::sync::atomic::Ordering

1.28.0 · Source§

impl Debug for core::fmt::Alignment

Source§

impl Debug for DebugAsHex

Source§

impl Debug for Sign

1.0.0 · Source§

impl Debug for bool

1.0.0 · Source§

impl Debug for char

1.0.0 · Source§

impl Debug for f16

1.0.0 · Source§

impl Debug for f32

1.0.0 · Source§

impl Debug for f64

1.0.0 · Source§

impl Debug for i8

1.0.0 · Source§

impl Debug for i16

1.0.0 · Source§

impl Debug for i32

1.0.0 · Source§

impl Debug for i64

1.0.0 · Source§

impl Debug for i128

1.0.0 · Source§

impl Debug for isize

Source§

impl Debug for !

1.0.0 · Source§

impl Debug for str

1.0.0 · Source§

impl Debug for u8

1.0.0 · Source§

impl Debug for u16

1.0.0 · Source§

impl Debug for u32

1.0.0 · Source§

impl Debug for u64

1.0.0 · Source§

impl Debug for u128

1.0.0 · Source§

impl Debug for ()

1.0.0 · Source§

impl Debug for usize

1.28.0 · Source§

impl Debug for Layout

1.0.0 · Source§

impl Debug for TypeId

1.95.0 · Source§

impl Debug for float16x4_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.95.0 · Source§

impl Debug for float16x8_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for float32x2_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for float32x2x2_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for float32x4_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for float32x4x2_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for float64x1_t

Available on AArch64 or target_arch=arm64ec only.
1.59.0 · Source§

impl Debug for float64x1x2_t

Available on AArch64 or target_arch=arm64ec only.
1.59.0 · Source§

impl Debug for float64x1x3_t

Available on AArch64 or target_arch=arm64ec only.
1.59.0 · Source§

impl Debug for float64x1x4_t

Available on AArch64 or target_arch=arm64ec only.
1.59.0 · Source§

impl Debug for float64x2_t

Available on AArch64 or target_arch=arm64ec only.
1.59.0 · Source§

impl Debug for float64x2x2_t

Available on AArch64 or target_arch=arm64ec only.
1.59.0 · Source§

impl Debug for float64x2x3_t

Available on AArch64 or target_arch=arm64ec only.
1.59.0 · Source§

impl Debug for float64x2x4_t

Available on AArch64 or target_arch=arm64ec only.
1.59.0 · Source§

impl Debug for int8x8_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for int8x8x2_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for int8x16_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for int8x16x2_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for int16x4_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for int16x4x2_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for int16x8_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for int16x8x2_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for int32x2_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for int32x2x2_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for int32x4_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for int32x4x2_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for int64x1_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for int64x2_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for poly8x8_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for poly8x16_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for poly16x4_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for poly16x8_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for poly64x1_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for poly64x2_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for uint8x8_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for uint8x8x2_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for uint8x16_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for uint16x4_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for uint16x8_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for uint32x2_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for uint32x4_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for uint64x1_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.59.0 · Source§

impl Debug for uint64x2_t

Available on (AArch64 or target_arch=arm64ec or target feature v7) and (ARM or AArch64 or target_arch=arm64ec) only.
1.34.0 · Source§

impl Debug for TryFromSliceError

1.16.0 · Source§

impl Debug for EscapeDefault

Source§

impl Debug for ByteStr

1.13.0 · Source§

impl Debug for BorrowError

1.13.0 · Source§

impl Debug for BorrowMutError

1.34.0 · Source§

impl Debug for CharTryFromError

1.9.0 · Source§

impl Debug for DecodeUtf16Error

1.20.0 · Source§

impl Debug for EscapeDebug

1.3.0 · Source§

impl Debug for CStr

Shows the underlying bytes as a normal string, with invalid UTF-8 presented as hex escape sequences.

1.0.0 · Source§

impl Debug for ParseIntError

1.34.0 · Source§

impl Debug for TryFromIntError

1.0.0 · Source§

impl Debug for RangeFull

1.10.0 · Source§

impl Debug for Location<'_>

1.81.0 · Source§

impl Debug for PanicMessage<'_>

Source§

impl Debug for core::ptr::Alignment

1.38.0 · Source§

impl Debug for Chars<'_>

1.0.0 · Source§

impl Debug for Utf8Error

1.3.0 · Source§

impl Debug for AtomicBool

1.34.0 · Source§

impl Debug for AtomicU8

1.34.0 · Source§

impl Debug for AtomicU16

1.34.0 · Source§

impl Debug for AtomicU32

1.34.0 · Source§

impl Debug for AtomicU64

1.3.0 · Source§

impl Debug for AtomicUsize

1.27.0 · Source§

impl Debug for Duration

1.66.0 · Source§

impl Debug for TryFromFloatSecsError

1.0.0 · Source§

impl Debug for Arguments<'_>

1.0.0 · Source§

impl Debug for Error

Source§

impl Debug for FormattingOptions

1.0.0 · Source§

impl Debug for dyn Any

1.0.0 · Source§

impl Debug for dyn Any + Send

1.28.0 · Source§

impl Debug for dyn Any + Send + Sync

1.10.0 · Source§

impl<'a> Debug for PanicInfo<'a>

Source§

impl<'a> Debug for CharSearcher<'a>

1.0.0 · Source§

impl<'a> Debug for Bytes<'a>

1.0.0 · Source§

impl<'a> Debug for CharIndices<'a>

Source§

impl<'a, 'b> Debug for StrSearcher<'a, 'b>

1.0.0 · Source§

impl<'a, A: Debug + 'a> Debug for core::option::Iter<'a, A>

1.0.0 · Source§

impl<'a, A: Debug + 'a> Debug for core::option::IterMut<'a, A>

1.51.0 · Source§

impl<'a, P: Pattern<Searcher<'a>: Debug>> Debug for SplitInclusive<'a, P>

1.0.0 · Source§

impl<'a, T: Debug + 'a> Debug for Chunks<'a, T>

1.31.0 · Source§

impl<'a, T: Debug + 'a> Debug for ChunksExact<'a, T>

1.31.0 · Source§

impl<'a, T: Debug + 'a> Debug for ChunksExactMut<'a, T>

1.0.0 · Source§

impl<'a, T: Debug + 'a> Debug for ChunksMut<'a, T>

1.0.0 · Source§

impl<'a, T: Debug + 'a> Debug for Windows<'a, T>

1.0.0 · Source§

impl<A: Debug> Debug for core::option::IntoIter<A>

1.0.0 · Source§

impl<A: Debug, B: Debug> Debug for Chain<A, B>

1.0.0 · Source§

impl<A: Debug, B: Debug> Debug for Zip<A, B>

1.55.0 · Source§

impl<B: Debug, C: Debug> Debug for ControlFlow<B, C>

Source§

impl<Dyn: PointeeSized> Debug for DynMetadata<Dyn>

1.34.0 · Source§

impl<F> Debug for core::iter::FromFn<F>

1.93.0 · Source§

impl<F> Debug for core::fmt::FromFn<F>
where F: Fn(&mut Formatter<'_>) -> Result,

1.9.0 · Source§

impl<I> Debug for DecodeUtf16<I>
where I: Iterator<Item = u16> + Debug,

1.1.0 · Source§

impl<I: Debug> Debug for Cloned<I>

1.36.0 · Source§

impl<I: Debug> Debug for Copied<I>

1.0.0 · Source§

impl<I: Debug> Debug for Enumerate<I>

1.0.0 · Source§

impl<I: Debug> Debug for Fuse<I>

1.0.0 · Source§

impl<I: Debug> Debug for Skip<I>

1.28.0 · Source§

impl<I: Debug> Debug for StepBy<I>

1.0.0 · Source§

impl<I: Debug> Debug for Take<I>

1.9.0 · Source§

impl<I: Debug, F> Debug for Map<I, F>

1.9.0 · Source§

impl<I: Debug, P> Debug for Filter<I, P>

1.9.0 · Source§

impl<I: Debug, P> Debug for TakeWhile<I, P>

1.9.0 · Source§

impl<I: Debug, U, F> Debug for FlatMap<I, U, F>
where U: IntoIterator<IntoIter: Debug>,

1.0.0 · Source§

impl<Idx: Debug> Debug for Range<Idx>

1.0.0 · Source§

impl<Idx: Debug> Debug for RangeFrom<Idx>

1.26.0 · Source§

impl<Idx: Debug> Debug for RangeInclusive<Idx>

1.0.0 · Source§

impl<Idx: Debug> Debug for RangeTo<Idx>

1.26.0 · Source§

impl<Idx: Debug> Debug for RangeToInclusive<Idx>

Source§

impl<P: Debug + ?Sized> Debug for MaybeDangling<P>

1.21.0 · Source§

impl<T> Debug for Discriminant<T>

1.28.0 · Source§

impl<T> Debug for NonZero<T>
where T: ZeroablePrimitive + Debug,

1.41.0 · Source§

impl<T> Debug for MaybeUninit<T>

1.0.0 · Source§

impl<T: Copy + Debug> Debug for Cell<T>

1.0.0 · Source§

impl<T: PointeeSized + Debug> Debug for &T

1.0.0 · Source§

impl<T: PointeeSized + Debug> Debug for &mut T

1.0.0 · Source§

impl<T: PointeeSized> Debug for *const T

1.0.0 · Source§

impl<T: PointeeSized> Debug for *mut T

1.25.0 · Source§

impl<T: PointeeSized> Debug for NonNull<T>

Source§

impl<T: Debug + NumBufferTrait> Debug for NumBuffer<T>

1.20.0 · Source§

impl<T: Debug + ?Sized> Debug for ManuallyDrop<T>

1.17.0 · Source§

impl<T: Debug> Debug for Bound<T>

1.0.0 · Source§

impl<T: Debug> Debug for Option<T>

1.0.0 · Source§

impl<T: Debug> Debug for [T]

1.0.0 · Source§

impl<T: Debug> Debug for (T₁, T₂, …, Tₙ)

This trait is implemented for tuples up to twelve items long.

1.0.0 · Source§

impl<T: Debug> Debug for Rev<T>

1.9.0 · Source§

impl<T: Debug> Debug for core::slice::Iter<'_, T>

1.9.0 · Source§

impl<T: Debug> Debug for core::slice::IterMut<'_, T>

1.0.0 · Source§

impl<T: Debug, E: Debug> Debug for Result<T, E>

1.0.0 · Source§

impl<T: Debug, const N: usize> Debug for [T; N]

1.40.0 · Source§

impl<T: Debug, const N: usize> Debug for core::array::IntoIter<T, N>

1.0.0 · Source§

impl<T: ?Sized + Debug> Debug for Ref<'_, T>

1.0.0 · Source§

impl<T: ?Sized + Debug> Debug for RefCell<T>

1.0.0 · Source§

impl<T: ?Sized + Debug> Debug for RefMut<'_, T>

Source§

impl<T: ?Sized> Debug for SyncUnsafeCell<T>

1.9.0 · Source§

impl<T: ?Sized> Debug for UnsafeCell<T>

1.0.0 · Source§

impl<T: ?Sized> Debug for PhantomData<T>