Trait alloc::fmt::Debug1.0.0 [] [src]

#[lang = "debug_trait"]
pub trait Debug { fn fmt(&self, f: &mut Formatter) -> Result<(), Error>; }

? 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 ).

Examples

Deriving an implementation:

#[derive(Debug)]
struct Point {
    x: i32,
    y: i32,
}

let origin = Point { x: 0, y: 0 };

println!("The origin is: {:?}", origin);

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 {
        write!(f, "Point {{ x: {}, y: {} }}", self.x, self.y)
    }
}

let origin = Point { x: 0, y: 0 };

println!("The origin is: {:?}", origin);

This outputs:

The origin is: Point { x: 0, y: 0 }

There are a number of debug_* methods on Formatter 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 };

println!("The origin is: {:#?}", origin);

This outputs:

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 {
        write!(f, "({:?}, {:?})", self.longitude, self.latitude)
    }
}

assert_eq!("(1.987, 2.983)".to_owned(),
           format!("{:?}", Position { longitude: 1.987, latitude: 2.983, }));

Implementations on Foreign Types

impl Debug for i64x4
[src]

impl Debug for EscapeDefault
[src]

impl Debug for NonZeroU16
[src]

impl Debug for AtomicU16
[src]

impl<'a, T> Debug for Pin<'a, T> where
    T: Debug + ?Sized
[src]

impl Debug for InvalidSequence
[src]

impl Debug for f64x8
[src]

impl Debug for i8x32
[src]

impl Debug for f64x4
[src]

impl Debug for i16x8
[src]

impl<T> Debug for Reverse<T> where
    T: Debug
[src]

impl<T> Debug for NonZero<T> where
    T: Zeroable + Debug
[src]

impl Debug for NonZeroIsize
[src]

impl Debug for i32x16
[src]

impl<'a> Debug for PanicInfo<'a>
[src]

impl Debug for EscapeDefault
[src]

impl<Idx> Debug for RangeToInclusive<Idx> where
    Idx: Debug
[src]

impl<T, E> Debug for Result<T, E> where
    E: Debug,
    T: Debug
[src]

impl<I, P> Debug for SkipWhile<I, P> where
    I: Debug
[src]

impl Debug for AtomicI64
[src]

impl<'a, T> Debug for Iter<'a, T> where
    T: 'a + Debug
[src]

impl Debug for u32x16
[src]

impl Debug for b8x64
[src]

impl Debug for u8x64
[src]

impl Debug for AtomicBool
[src]

impl<A, B> Debug for Chain<A, B> where
    A: Debug,
    B: Debug
[src]

impl Debug for u16x32
[src]

impl Debug for RangeFull
[src]

impl<T> Debug for NonNull<T> where
    T: ?Sized
[src]

impl Debug for NonZeroI32
[src]

impl<I, U, F> Debug for FlatMap<I, U, F> where
    I: Debug,
    U: IntoIterator,
    <U as IntoIterator>::IntoIter: Debug
[src]

impl<F> Debug for RepeatWith<F> where
    F: Debug
[src]

impl<A, B> Debug for Zip<A, B> where
    A: Debug,
    B: Debug
[src]

impl Debug for AtomicI32
[src]

impl<I> Debug for Skip<I> where
    I: Debug
[src]

impl Debug for i32x4
[src]

impl Debug for ParseFloatError
[src]

impl<I> Debug for Fuse<I> where
    I: Debug
[src]

impl<I, St, F> Debug for Scan<I, St, F> where
    I: Debug,
    St: Debug
[src]

impl Debug for i32x2
[src]

impl Debug for __m128i
[src]

impl<T> Debug for ManuallyDrop<T> where
    T: Debug
[src]

impl<I> Debug for Cloned<I> where
    I: Debug
[src]

impl Debug for i16x4
[src]

impl Debug for u16x4
[src]

impl Debug for i16x2
[src]

impl Debug for NonZeroU128
[src]

impl<Idx> Debug for RangeTo<Idx> where
    Idx: Debug
[src]

impl Debug for u8x4
[src]

impl Debug for NonZeroI8
[src]

impl Debug for u32x8
[src]

impl Debug for BorrowError
[src]

impl Debug for u32x4
[src]

impl Debug for AtomicI16
[src]

impl Debug for AtomicU8
[src]

impl Debug for f64x2
[src]

impl Debug for NonZeroI128
[src]

impl Debug for __m256
[src]

impl Debug for b8x4
[src]

impl Debug for __m64
[src]

impl<T> Debug for Bound<T> where
    T: Debug
[src]

impl Debug for AtomicI8
[src]

impl Debug for AtomicUsize
[src]

impl<I> Debug for StepBy<I> where
    I: Debug
[src]

impl Debug for Ordering
[src]

impl<'a, A> Debug for IterMut<'a, A> where
    A: 'a + Debug
[src]

impl Debug for u16x16
[src]

impl Debug for Any + 'static
[src]

impl<I, F> Debug for Inspect<I, F> where
    I: Debug
[src]

impl Debug for f32x8
[src]

impl Debug for TypeId
[src]

impl Debug for NonZeroU32
[src]

impl Debug for i8x8
[src]

impl Debug for b8x2
[src]

impl<H> Debug for BuildHasherDefault<H>
[src]

impl<'b, T> Debug for Ref<'b, T> where
    T: Debug + ?Sized
[src]

impl<I> Debug for Cycle<I> where
    I: Debug
[src]

impl<I> Debug for Enumerate<I> where
    I: Debug
[src]

impl Debug for u8x2
[src]

impl<A> Debug for Repeat<A> where
    A: Debug
[src]

impl<T> Debug for AtomicPtr<T>
[src]

impl Debug for EscapeUnicode
[src]

impl Debug for NonZeroI64
[src]

impl Debug for u16x2
[src]

impl<T> Debug for Empty<T>
[src]

impl Debug for BorrowMutError
[src]

impl Debug for EscapeDebug
[src]

impl<T> Debug for Cell<T> where
    T: Copy + Debug
[src]

impl Debug for NonZeroUsize
[src]

impl<I, F> Debug for Map<I, F> where
    I: Debug
[src]

impl Debug for ParseIntError
[src]

impl Debug for NonZeroU8
[src]

impl Debug for i8x16
[src]

impl Debug for FpCategory
[src]

impl Debug for ParseCharError
[src]

impl<Idx> Debug for RangeFrom<Idx> where
    Idx: Debug
[src]

impl Debug for f32x2
[src]

impl Debug for u64x8
[src]

impl<Y, R> Debug for GeneratorState<Y, R> where
    R: Debug,
    Y: Debug
[src]

impl<Idx> Debug for RangeInclusive<Idx> where
    Idx: Debug
[src]

impl Debug for u16x8
[src]

impl<T> Debug for Wrapping<T> where
    T: Debug
[src]

impl Debug for u8x16
[src]

impl Debug for b8x16
[src]

impl<I> Debug for DecodeUtf8<I> where
    I: Iterator<Item = u8> + Debug
[src]

impl Debug for CharTryFromError
[src]

impl<I, P> Debug for Filter<I, P> where
    I: Debug
[src]

impl Debug for TryFromIntError
[src]

impl Debug for u64x2
[src]

impl<T> Debug for Discriminant<T>
[src]

impl<I, U> Debug for Flatten<I> where
    I: Iterator + Debug,
    U: Iterator + Debug,
    <I as Iterator>::Item: IntoIterator,
    <<I as Iterator>::Item as IntoIterator>::IntoIter == U,
    <<I as Iterator>::Item as IntoIterator>::Item == <U as Iterator>::Item
[src]

impl Debug for i16x16
[src]

impl<I, P> Debug for TakeWhile<I, P> where
    I: Debug
[src]

impl<T> Debug for RefCell<T> where
    T: Debug + ?Sized
[src]

impl<T> Debug for IntoIter<T> where
    T: Debug
[src]

impl Debug for i8x2
[src]

impl<T> Debug for Rev<T> where
    T: Debug
[src]

impl Debug for u8x8
[src]

impl Debug for f32x4
[src]

impl Debug for i32x8
[src]

impl Debug for __m256i
[src]

impl<T> Debug for PhantomData<T> where
    T: ?Sized
[src]

impl Debug for AtomicIsize
[src]

impl<'a, A> Debug for Iter<'a, A> where
    A: 'a + Debug
[src]

impl Debug for u32x2
[src]

impl Debug for i64x2
[src]

impl Debug for SipHasher
[src]

impl Debug for i16x32
[src]

impl<'a> Debug for Location<'a>
[src]

impl<'b, T> Debug for RefMut<'b, T> where
    T: Debug + ?Sized
[src]

impl Debug for u8x32
[src]

impl<T> Debug for Once<T> where
    T: Debug
[src]

impl<T> Debug for UnsafeCell<T> where
    T: Debug + ?Sized
[src]

impl Debug for NonZeroI16
[src]

impl Debug for NoneError
[src]

impl Debug for b8x32
[src]

impl Debug for Any + 'static + Send
[src]

impl Debug for b8x8
[src]

impl Debug for u64x4
[src]

impl Debug for TryFromSliceError
[src]

impl<A> Debug for IntoIter<A> where
    A: Debug
[src]

impl<T> Debug for Unique<T> where
    T: ?Sized
[src]

impl Debug for __m256d
[src]

impl Debug for f32x16
[src]

impl Debug for AtomicU64
[src]

impl Debug for i64x8
[src]

impl Debug for AtomicU32
[src]

impl Debug for Ordering
[src]

impl<Idx> Debug for Range<Idx> where
    Idx: Debug
[src]

impl Debug for Alignment
[src]

impl<'a, T> Debug for IterMut<'a, T> where
    T: 'a + Debug
[src]

impl<I> Debug for Take<I> where
    I: Debug
[src]

impl Debug for Duration
[src]

impl Debug for __m128d
[src]

impl Debug for i8x64
[src]

impl Debug for __m128
[src]

impl<T> Debug for Option<T> where
    T: Debug
[src]

impl Debug for NonZeroU64
[src]

impl<I> Debug for Peekable<I> where
    I: Iterator + Debug,
    <I as Iterator>::Item: Debug
[src]

impl<I, F> Debug for FilterMap<I, F> where
    I: Debug
[src]

impl Debug for i8x4
[src]

impl Debug for ToLowercase
[src]

impl Debug for UnicodeVersion
[src]

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

impl<'a> Debug for Utf8LossyChunk<'a>
[src]

impl Debug for ToUppercase
[src]

impl Debug for DecodeUtf16Error
[src]

impl Debug for Utf8Lossy
[src]

Implementors