<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="generator" content="rustdoc">
    <meta name="description" content="API documentation for the Rust `Debug` trait in crate `collections`.">
    <meta name="keywords" content="rust, rustlang, rust-lang, Debug">

    <title>collections::fmt::Debug - Rust</title>

    <link rel="stylesheet" type="text/css" href="../../rustdoc.css">
    <link rel="stylesheet" type="text/css" href="../../main.css">

    <link rel="shortcut icon" href="https://doc.rust-lang.org/favicon.ico">
    
</head>
<body class="rustdoc">
    <!--[if lte IE 8]>
    <div class="warning">
        This old browser is unsupported and will most likely display funky
        things.
    </div>
    <![endif]-->

    

    <nav class="sidebar">
        <a href='../../collections/index.html'><img src='https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png' alt='' width='100'></a>
        <p class='location'><a href='../index.html'>collections</a>::<wbr><a href='index.html'>fmt</a></p><script>window.sidebarCurrent = {name: 'Debug', ty: 'trait', relpath: ''};</script><script defer src="sidebar-items.js"></script>
    </nav>

    <nav class="sub">
        <form class="search-form js-only">
            <div class="search-container">
                <input class="search-input" name="search"
                       autocomplete="off"
                       placeholder="Click or press ‘S’ to search, ‘?’ for more options…"
                       type="search">
            </div>
        </form>
    </nav>

    <section id='main' class="content trait">
<h1 class='fqn'><span class='in-band'>Trait <a href='../index.html'>collections</a>::<wbr><a href='index.html'>fmt</a>::<wbr><a class='trait' href=''>Debug</a></span><span class='out-of-band'><span id='render-detail'>
            <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
                [<span class='inner'>&#x2212;</span>]
            </a>
        </span><a id='src-34764' class='srclink' href='../../core/fmt/trait.Debug.html?gotosrc=34764' title='goto source code'>[src]</a></span></h1>
<pre class='rust trait'>pub trait Debug {
    fn <a href='#tymethod.fmt' class='fnname'>fmt</a>(&amp;self, &amp;mut <a class='struct' href='../../collections/fmt/struct.Formatter.html' title='collections::fmt::Formatter'>Formatter</a>) -&gt; <a class='enum' href='../../core/result/enum.Result.html' title='core::result::Result'>Result</a>&lt;(), <a class='struct' href='../../collections/fmt/struct.Error.html' title='collections::fmt::Error'>Error</a>&gt;;
}</pre><div class='docblock'><p>Format trait for the <code>?</code> character.</p>

<p><code>Debug</code> should format the output in a programmer-facing, debugging context.</p>

<p>Generally speaking, you should just <code>derive</code> a <code>Debug</code> implementation.</p>

<p>When used with the alternate format specifier <code>#?</code>, the output is pretty-printed.</p>

<p>For more information on formatters, see <a href="../../std/fmt/index.html">the module-level documentation</a>.</p>

<p>This trait can be used with <code>#[derive]</code>.</p>

<h1 id='examples' class='section-header'><a href='#examples'>Examples</a></h1>
<p>Deriving an implementation:</p>
<span class='rusttest'>fn main() {
    #[derive(Debug)]
    struct Point {
        x: i32,
        y: i32,
    }
    
    let origin = Point { x: 0, y: 0 };
    
    println!(&quot;The origin is: {:?}&quot;, origin);
    
}</span><pre class='rust rust-example-rendered'>
<span class='attribute'>#[<span class='ident'>derive</span>(<span class='ident'>Debug</span>)]</span>
<span class='kw'>struct</span> <span class='ident'>Point</span> {
    <span class='ident'>x</span>: <span class='ident'>i32</span>,
    <span class='ident'>y</span>: <span class='ident'>i32</span>,
}

<span class='kw'>let</span> <span class='ident'>origin</span> <span class='op'>=</span> <span class='ident'>Point</span> { <span class='ident'>x</span>: <span class='number'>0</span>, <span class='ident'>y</span>: <span class='number'>0</span> };

<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;The origin is: {:?}&quot;</span>, <span class='ident'>origin</span>);</pre>

<p>Manually implementing:</p>
<span class='rusttest'>fn main() {
    use std::fmt;
    
    struct Point {
        x: i32,
        y: i32,
    }
    
    impl fmt::Debug for Point {
        fn fmt(&amp;self, f: &amp;mut fmt::Formatter) -&gt; fmt::Result {
            write!(f, &quot;Point {{ x: {}, y: {} }}&quot;, self.x, self.y)
        }
    }
    
    let origin = Point { x: 0, y: 0 };
    
    println!(&quot;The origin is: {:?}&quot;, origin);
    
}</span><pre class='rust rust-example-rendered'>
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>fmt</span>;

<span class='kw'>struct</span> <span class='ident'>Point</span> {
    <span class='ident'>x</span>: <span class='ident'>i32</span>,
    <span class='ident'>y</span>: <span class='ident'>i32</span>,
}

<span class='kw'>impl</span> <span class='ident'>fmt</span>::<span class='ident'>Debug</span> <span class='kw'>for</span> <span class='ident'>Point</span> {
    <span class='kw'>fn</span> <span class='ident'>fmt</span>(<span class='kw-2'>&amp;</span><span class='self'>self</span>, <span class='ident'>f</span>: <span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='ident'>fmt</span>::<span class='ident'>Formatter</span>) <span class='op'>-&gt;</span> <span class='ident'>fmt</span>::<span class='prelude-ty'>Result</span> {
        <span class='macro'>write</span><span class='macro'>!</span>(<span class='ident'>f</span>, <span class='string'>&quot;Point {{ x: {}, y: {} }}&quot;</span>, <span class='self'>self</span>.<span class='ident'>x</span>, <span class='self'>self</span>.<span class='ident'>y</span>)
    }
}

<span class='kw'>let</span> <span class='ident'>origin</span> <span class='op'>=</span> <span class='ident'>Point</span> { <span class='ident'>x</span>: <span class='number'>0</span>, <span class='ident'>y</span>: <span class='number'>0</span> };

<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;The origin is: {:?}&quot;</span>, <span class='ident'>origin</span>);</pre>

<p>This outputs:</p>

<pre><code class="language-text">The origin is: Point { x: 0, y: 0 }
</code></pre>

<p>There are a number of <code>debug_*</code> methods on <code>Formatter</code> to help you with manual
implementations, such as <a href="../std/fmt/struct.Formatter.html#method.debug_struct"><code>debug_struct</code></a>.</p>

<p><code>Debug</code> implementations using either <code>derive</code> or the debug builder API
on <code>Formatter</code> support pretty printing using the alternate flag: <code>{:#?}</code>.</p>

<p>Pretty printing with <code>#?</code>:</p>
<span class='rusttest'>fn main() {
    #[derive(Debug)]
    struct Point {
        x: i32,
        y: i32,
    }
    
    let origin = Point { x: 0, y: 0 };
    
    println!(&quot;The origin is: {:#?}&quot;, origin);
    
}</span><pre class='rust rust-example-rendered'>
<span class='attribute'>#[<span class='ident'>derive</span>(<span class='ident'>Debug</span>)]</span>
<span class='kw'>struct</span> <span class='ident'>Point</span> {
    <span class='ident'>x</span>: <span class='ident'>i32</span>,
    <span class='ident'>y</span>: <span class='ident'>i32</span>,
}

<span class='kw'>let</span> <span class='ident'>origin</span> <span class='op'>=</span> <span class='ident'>Point</span> { <span class='ident'>x</span>: <span class='number'>0</span>, <span class='ident'>y</span>: <span class='number'>0</span> };

<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;The origin is: {:#?}&quot;</span>, <span class='ident'>origin</span>);</pre>

<p>This outputs:</p>

<pre><code class="language-text">The origin is: Point {
    x: 0,
    y: 0
}
</code></pre>
</div>
            <h2 id='required-methods'>Required Methods</h2>
            <div class='methods'>
        <h3 id='tymethod.fmt' class='method stab '><code>fn <a href='#tymethod.fmt' class='fnname'>fmt</a>(&amp;self, &amp;mut <a class='struct' href='../../collections/fmt/struct.Formatter.html' title='collections::fmt::Formatter'>Formatter</a>) -&gt; <a class='enum' href='../../core/result/enum.Result.html' title='core::result::Result'>Result</a>&lt;(), <a class='struct' href='../../collections/fmt/struct.Error.html' title='collections::fmt::Error'>Error</a>&gt;</code></h3><div class='docblock'><p>Formats the value using the given formatter.</p>
</div></div>
        <h2 id='implementors'>Implementors</h2>
        <ul class='item-list' id='implementors-list'>
    <li><code>impl&lt;T&gt; <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a> for <a class='struct' href='../../collections/boxed/struct.Box.html' title='collections::boxed::Box'>Box</a>&lt;T&gt; <span class='where'>where T: <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a> + ?<a class='trait' href='../../core/marker/trait.Sized.html' title='core::marker::Sized'>Sized</a></span></code></li>
<li><code>impl&lt;T&gt; <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a> for <a class='struct' href='../../alloc/arc/struct.Weak.html' title='alloc::arc::Weak'>Weak</a>&lt;T&gt; <span class='where'>where T: <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a> + ?<a class='trait' href='../../core/marker/trait.Sized.html' title='core::marker::Sized'>Sized</a></span></code></li>
<li><code>impl&lt;T&gt; <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a> for <a class='struct' href='../../alloc/arc/struct.Arc.html' title='alloc::arc::Arc'>Arc</a>&lt;T&gt; <span class='where'>where T: <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a> + ?<a class='trait' href='../../core/marker/trait.Sized.html' title='core::marker::Sized'>Sized</a></span></code></li>
<li><code>impl&lt;T&gt; <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a> for <a class='struct' href='../../alloc/rc/struct.Rc.html' title='alloc::rc::Rc'>Rc</a>&lt;T&gt; <span class='where'>where T: <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a> + ?<a class='trait' href='../../core/marker/trait.Sized.html' title='core::marker::Sized'>Sized</a></span></code></li>
<li><code>impl&lt;T&gt; <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a> for <a class='struct' href='../../alloc/rc/struct.Weak.html' title='alloc::rc::Weak'>Weak</a>&lt;T&gt; <span class='where'>where T: <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a> + ?<a class='trait' href='../../core/marker/trait.Sized.html' title='core::marker::Sized'>Sized</a></span></code></li>
<li><code>impl&lt;T: <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a> + <a class='trait' href='../../core/cmp/trait.Ord.html' title='core::cmp::Ord'>Ord</a>&gt; <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a> for <a class='struct' href='../../collections/binary_heap/struct.BinaryHeap.html' title='collections::binary_heap::BinaryHeap'>BinaryHeap</a>&lt;T&gt;</code></li>
<li><code>impl&lt;K: <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a>, V: <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a>&gt; <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a> for <a class='struct' href='../../collections/struct.BTreeMap.html' title='collections::BTreeMap'>BTreeMap</a>&lt;K, V&gt;</code></li>
<li><code>impl&lt;T: <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a>&gt; <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a> for <a class='struct' href='../../collections/struct.BTreeSet.html' title='collections::BTreeSet'>BTreeSet</a>&lt;T&gt;</code></li>
<li><code>impl&lt;'a, B: ?<a class='trait' href='../../core/marker/trait.Sized.html' title='core::marker::Sized'>Sized</a>&gt; <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a> for <a class='enum' href='../../collections/borrow/enum.Cow.html' title='collections::borrow::Cow'>Cow</a>&lt;'a, B&gt; <span class='where'>where B: <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a> + <a class='trait' href='../../collections/borrow/trait.ToOwned.html' title='collections::borrow::ToOwned'>ToOwned</a>, B::Owned: <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a></span></code></li>
<li><code>impl&lt;E: <a class='trait' href='../../collections/enum_set/trait.CLike.html' title='collections::enum_set::CLike'>CLike</a> + <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a>&gt; <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a> for <a class='struct' href='../../collections/enum_set/struct.EnumSet.html' title='collections::enum_set::EnumSet'>EnumSet</a>&lt;E&gt;</code></li>
<li><code>impl&lt;A: <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a>&gt; <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a> for <a class='struct' href='../../collections/linked_list/struct.LinkedList.html' title='collections::linked_list::LinkedList'>LinkedList</a>&lt;A&gt;</code></li>
<li><code>impl <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a> for <a class='enum' href='../../rustc_unicode/u_str/enum.Utf16Item.html' title='rustc_unicode::u_str::Utf16Item'>Utf16Item</a></code></li>
<li><code>impl <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a> for <a class='struct' href='../../collections/string/struct.FromUtf8Error.html' title='collections::string::FromUtf8Error'>FromUtf8Error</a></code></li>
<li><code>impl <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a> for <a class='struct' href='../../collections/string/struct.FromUtf16Error.html' title='collections::string::FromUtf16Error'>FromUtf16Error</a></code></li>
<li><code>impl <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a> for <a class='struct' href='../../collections/string/struct.String.html' title='collections::string::String'>String</a></code></li>
<li><code>impl <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a> for <a class='enum' href='../../collections/string/enum.ParseError.html' title='collections::string::ParseError'>ParseError</a></code></li>
<li><code>impl&lt;T: <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a>&gt; <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a> for <a class='struct' href='../../collections/vec/struct.Vec.html' title='collections::vec::Vec'>Vec</a>&lt;T&gt;</code></li>
<li><code>impl&lt;T: <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a>&gt; <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a> for <a class='struct' href='../../collections/vec_deque/struct.VecDeque.html' title='collections::vec_deque::VecDeque'>VecDeque</a>&lt;T&gt;</code></li>
<li><code>impl&lt;T: <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a>&gt; <a class='trait' href='../../collections/fmt/trait.Debug.html' title='collections::fmt::Debug'>Debug</a> for <a class='enum' href='../../collections/enum.Bound.html' title='collections::Bound'>Bound</a>&lt;T&gt;</code></li>
</ul><script type="text/javascript" async
                              src="../../implementors/core/fmt/trait.Debug.js">
                      </script></section>
    <section id='search' class="content hidden"></section>

    <section class="footer"></section>

    <aside id="help" class="hidden">
        <div>
            <h1 class="hidden">Help</h1>

            <div class="shortcuts">
                <h2>Keyboard Shortcuts</h2>

                <dl>
                    <dt>?</dt>
                    <dd>Show this help dialog</dd>
                    <dt>S</dt>
                    <dd>Focus the search field</dd>
                    <dt>&larrb;</dt>
                    <dd>Move up in search results</dd>
                    <dt>&rarrb;</dt>
                    <dd>Move down in search results</dd>
                    <dt>&#9166;</dt>
                    <dd>Go to active search result</dd>
                </dl>
            </div>

            <div class="infos">
                <h2>Search Tricks</h2>

                <p>
                    Prefix searches with a type followed by a colon (e.g.
                    <code>fn:</code>) to restrict the search to a given type.
                </p>

                <p>
                    Accepted types are: <code>fn</code>, <code>mod</code>,
                    <code>struct</code>, <code>enum</code>,
                    <code>trait</code>, <code>type</code>, <code>macro</code>,
                    and <code>const</code>.
                </p>

                <p>
                    Search functions by type signature (e.g.
                    <code>vec -> usize</code>)
                </p>
            </div>
        </div>
    </aside>

    

    <script>
        window.rootPath = "../../";
        window.currentCrate = "collections";
        window.playgroundUrl = "https://play.rust-lang.org/";
    </script>
    <script src="../../jquery.js"></script>
    <script src="../../main.js"></script>
    <script src="../../playpen.js"></script>
    <script defer src="../../search-index.js"></script>
</body>
</html>