# Trait collections::fmt::Debug [−] [src]

    pub trait Debug {
        fn fmt(&self, &mut Formatter) -> Result<(), Error>;
    }

Format trait for the `?` character.

`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]`.

# Examples

Deriving an implementation:

fn main() { #[derive(Debug)] struct Point { x: i32, y: i32, } let origin = Point { x: 0, y: 0 }; println!("The origin is: {:?}", origin); }

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

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

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

Manually implementing:

fn main() { 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); }

    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 `#?`:

fn main() { #[derive(Debug)] struct Point { x: i32, y: i32, } let origin = Point { x: 0, y: 0 }; println!("The origin is: {:#?}", origin); }

    #[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

### `fn fmt(&self, &mut Formatter) -> Result<(), Error>`

Formats the value using the given formatter.

## Implementors

- `impl<T> Debug for Box<T> where T: Debug + ?Sized`
- `impl<T: Debug + Ord> Debug for BinaryHeap<T>`
- `impl<K: Debug, V: Debug> Debug for BTreeMap<K, V>`
- `impl<T: Debug> Debug for BTreeSet<T>`
- `impl<'a, B: ?Sized> Debug for Cow<'a, B> where B: Debug + ToOwned, B::Owned: Debug`
- `impl<E: CLike + Debug> Debug for EnumSet<E>`
- `impl Debug for Error`
- `impl<'a> Debug for Arguments<'a>`
- `impl<A: Debug> Debug for LinkedList<A>`
- `impl<'a, T> Debug for Chunks<'a, T> where T: 'a + Debug`
- `impl<'a, T> Debug for Windows<'a, T> where T: 'a + Debug`
- `impl<'a, T> Debug for Iter<'a, T> where T: 'a + Debug`
- `impl<'a, T> Debug for IterMut<'a, T> where T: 'a + Debug`
- `impl<'a, T, P> Debug for SplitMut<'a, T, P> where T: 'a + Debug, P: FnMut(&T) -> bool`
- `impl<'a, T> Debug for ChunksMut<'a, T> where T: 'a + Debug`
- `impl<'a, T, P> Debug for Split<'a, T, P> where T: 'a + Debug, P: FnMut(&T) -> bool`
- `impl<'a, T, P> Debug for SplitN<'a, T, P> where P: FnMut(&T) -> bool, T: 'a + Debug`
- `impl<'a, T, P> Debug for RSplitN<'a, T, P> where P: FnMut(&T) -> bool, T: 'a + Debug`
- `impl<'a, T, P> Debug for SplitNMut<'a, T, P> where T: 'a + Debug, P: FnMut(&T) -> bool`
- `impl<'a, T, P> Debug for RSplitNMut<'a, T, P> where T: 'a + Debug, P: FnMut(&T) -> bool`
- `impl Debug for Utf8Error`
- `impl<'a> Debug for Lines<'a>`
- `impl<'a> Debug for LinesAny<'a>`
- `impl Debug for CharRange`
- `impl<'a, P> Debug for Split<'a, P> where P: Pattern<'a>, P::Searcher: Debug`
- `impl<'a, P> Debug for RSplit<'a, P> where P: Pattern<'a>, P::Searcher: Debug`
- `impl<'a, P> Debug for SplitN<'a, P> where P: Pattern<'a>, P::Searcher: Debug`
- `impl<'a, P> Debug for RSplitN<'a, P> where P: Pattern<'a>, P::Searcher: Debug`
- `impl<'a, P> Debug for SplitTerminator<'a, P> where P: Pattern<'a>, P::Searcher: Debug`
- `impl<'a, P> Debug for RSplitTerminator<'a, P> where P: Pattern<'a>, P::Searcher: Debug`
- `impl<'a, P> Debug for Matches<'a, P> where P: Pattern<'a>, P::Searcher: Debug`
- `impl<'a, P> Debug for RMatches<'a, P> where P: Pattern<'a>, P::Searcher: Debug`
- `impl<'a, P> Debug for MatchIndices<'a, P> where P: Pattern<'a>, P::Searcher: Debug`
- `impl<'a, P> Debug for RMatchIndices<'a, P> where P: Pattern<'a>, P::Searcher: Debug`
- `impl<'a> Debug for Chars<'a>`
- `impl<'a> Debug for CharIndices<'a>`
- `impl<'a> Debug for Bytes<'a>`
- `impl Debug for ParseBoolError`
- `impl Debug for SearchStep`
- `impl<'a> Debug for CharSearcher<'a>`
- `impl<'a, 'b> Debug for CharSliceSearcher<'a, 'b>`
- `impl<'a, F> Debug for CharPredicateSearcher<'a, F> where F: FnMut(char) -> bool`
- `impl<'a, 'b> Debug for StrSearcher<'a, 'b>`
- `impl Debug for FromUtf8Error`
- `impl Debug for FromUtf16Error`
- `impl Debug for String`
- `impl Debug for ParseError`
- `impl<T: Debug> Debug for Vec<T>`
- `impl<T: Debug> Debug for VecDeque<T>`
- `impl Debug for RangeFull`
- `impl<Idx> Debug for Range<Idx> where Idx: Debug`
- `impl<Idx> Debug for RangeFrom<Idx> where Idx: Debug`
- `impl<Idx> Debug for RangeTo<Idx> where Idx: Debug`
- `impl<Idx> Debug for RangeInclusive<Idx> where Idx: Debug`
- `impl<Idx> Debug for RangeToInclusive<Idx> where Idx: Debug`
- `impl<T: Debug> Debug for Bound<T>`

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)