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.

Implementations on Foreign Types

impl Debug for DecodeUtf16Error
[src]

[src]

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

[src]

impl Debug for Utf8Lossy
[src]

[src]

impl Debug for UnicodeVersion
[src]

[src]

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

[src]

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

[src]

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

[src]

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

[src]

impl Debug for SipHasher
[src]

[src]

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

[src]

impl Debug for EscapeUnicode
[src]

[src]

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

[src]

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

[src]

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

[src]

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

[src]

impl Debug for InvalidSequence
[src]

[src]

impl Debug for AtomicI64
[src]

[src]

impl Debug for AtomicI8
[src]

[src]

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

[src]

impl Debug for AtomicU64
[src]

[src]

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

[src]

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

[src]

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

[src]

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

[src]

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

[src]

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

[src]

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

[src]

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

[src]

impl Debug for EscapeDefault
[src]

[src]

impl Debug for ParseCharError
[src]

[src]

impl Debug for TypeId
[src]

[src]

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

[src]

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

[src]

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

[src]

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

[src]

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

[src]

impl Debug for EscapeDebug
[src]

[src]

impl Debug for Ordering
[src]

[src]

impl Debug for TryFromIntError
[src]

[src]

impl Debug for NoneError
[src]

[src]

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

[src]

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

[src]

impl Debug for Ordering
[src]

[src]

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

[src]

impl Debug for SipHasher24
[src]

[src]

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

[src]

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

[src]

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

[src]

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

[src]

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

[src]

impl Debug for AtomicI16
[src]

[src]

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

[src]

impl Debug for SipHasher13
[src]

[src]

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

[src]

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

[src]

impl Debug for BorrowMutError
[src]

[src]

impl Debug for Any + 'static
[src]

[src]

impl Debug for RangeFull
[src]

[src]

impl Debug for FpCategory
[src]

[src]

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

[src]

impl Debug for CharTryFromError
[src]

[src]

impl Debug for AtomicUsize
[src]

[src]

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

[src]

impl Debug for ParseFloatError
[src]

[src]

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

[src]

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

[src]

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

[src]

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

[src]

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

[src]

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

[src]

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

[src]

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

[src]

impl Debug for ParseIntError
[src]

[src]

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

[src]

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

[src]

impl Debug for AtomicI32
[src]

[src]

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

[src]

impl Debug for AtomicIsize
[src]

[src]

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

[src]

impl Debug for AtomicBool
[src]

[src]

impl Debug for AtomicU8
[src]

[src]

impl Debug for Infallible
[src]

[src]

impl Debug for Alignment
[src]

[src]

impl Debug for BorrowError
[src]

[src]

impl Debug for AtomicU16
[src]

[src]

impl Debug for AtomicU32
[src]

[src]

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

[src]

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

[src]

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

[src]

Implementors