<!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 `Formatter` struct in crate `std`."> <meta name="keywords" content="rust, rustlang, rust-lang, Formatter"> <title>std::fmt::Formatter - Rust</title> <link rel="stylesheet" type="text/css" href="../../normalize.css"> <link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle"> <link rel="stylesheet" type="text/css" href="../../dark.css"> <link rel="stylesheet" type="text/css" href="../../main.css" id="themeStyle"> <script src="../../storage.js"></script> <link rel="shortcut icon" href="https://doc.rust-lang.org/favicon.ico"> </head> <body class="rustdoc struct"> <!--[if lte IE 8]> <div class="warning"> This old browser is unsupported and will most likely display funky things. </div> <![endif]--> <nav class="sidebar"> <div class="sidebar-menu">☰</div> <a href='../../std/index.html'><img src='https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png' alt='logo' width='100'></a> <p class='location'>Struct Formatter</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#methods">Methods</a><div class="sidebar-links"><a href="#method.pad_integral">pad_integral</a><a href="#method.pad">pad</a><a href="#method.write_str">write_str</a><a href="#method.write_fmt">write_fmt</a><a href="#method.flags">flags</a><a href="#method.fill">fill</a><a href="#method.align">align</a><a href="#method.width">width</a><a href="#method.precision">precision</a><a href="#method.sign_plus">sign_plus</a><a href="#method.sign_minus">sign_minus</a><a href="#method.alternate">alternate</a><a href="#method.sign_aware_zero_pad">sign_aware_zero_pad</a><a href="#method.debug_struct">debug_struct</a><a href="#method.debug_tuple">debug_tuple</a><a href="#method.debug_list">debug_list</a><a href="#method.debug_set">debug_set</a><a href="#method.debug_map">debug_map</a></div><a class="sidebar-title" href="#implementations">Trait Implementations</a><div class="sidebar-links"><a href="#impl-Write">Write</a></div></div><p class='location'><a href='../index.html'>std</a>::<wbr><a href='index.html'>fmt</a></p><script>window.sidebarCurrent = {name: 'Formatter', ty: 'struct', relpath: ''};</script><script defer src="sidebar-items.js"></script></div> </nav> <div class="theme-picker"> <button id="theme-picker" aria-label="Pick another theme!"> <img src="../../brush.svg" width="18" alt="Pick another theme!"> </button> <div id="theme-choices"></div> </div> <script src="../../theme.js"></script> <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"> <h1 class='fqn'><span class='in-band'>Struct <a href='../index.html'>std</a>::<wbr><a href='index.html'>fmt</a>::<wbr><a class="struct" href=''>Formatter</a></span><span class='out-of-band'><span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span><span id='render-detail'> <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs"> [<span class='inner'>−</span>] </a> </span><a class='srclink' href='../../src/core/fmt/mod.rs.html#250-260' title='goto source code'>[src]</a></span></h1> <pre class='rust struct'>pub struct Formatter<'a> { /* fields omitted */ }</pre><div class='docblock'><p>A struct to represent both where to emit formatting strings to and how they should be formatted. A mutable version of this is passed to all formatting traits.</p> </div> <h2 id='methods' class='small-section-header'> Methods<a href='#methods' class='anchor'></a> </h2> <h3 id='impl' class='impl'><span class='in-band'><code>impl<'a> <a class="struct" href="../../std/fmt/struct.Formatter.html" title="struct std::fmt::Formatter">Formatter</a><'a></code><a href='#impl' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/fmt/mod.rs.html#1044-1535' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.pad_integral' class="method"><span id='pad_integral.v' class='invisible'><code>pub fn <a href='#method.pad_integral' class='fnname'>pad_integral</a>(<br> &mut self, <br> is_nonnegative: <a class="primitive" href="../primitive.bool.html">bool</a>, <br> prefix: &<a class="primitive" href="../primitive.str.html">str</a>, <br> buf: &<a class="primitive" href="../primitive.str.html">str</a><br>) -> <a class="enum" href="../../std/result/enum.Result.html" title="enum std::result::Result">Result</a><<a class="primitive" href="../primitive.unit.html">()</a>, <a class="struct" href="../../std/fmt/struct.Error.html" title="struct std::fmt::Error">Error</a>></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/fmt/mod.rs.html#1117-1174' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Performs the correct padding for an integer which has already been emitted into a str. The str should <em>not</em> contain the sign for the integer, that will be added by this method.</p> <h1 id="arguments" class="section-header"><a href="#arguments">Arguments</a></h1> <ul> <li>is_nonnegative - whether the original integer was either positive or zero.</li> <li>prefix - if the '#' character (Alternate) is provided, this is the prefix to put in front of the number.</li> <li>buf - the byte array that the number has been formatted into</li> </ul> <p>This function will correctly account for the flags provided as well as the minimum width. It will not take precision into account.</p> </div><h4 id='method.pad' class="method"><span id='pad.v' class='invisible'><code>pub fn <a href='#method.pad' class='fnname'>pad</a>(&mut self, s: &<a class="primitive" href="../primitive.str.html">str</a>) -> <a class="enum" href="../../std/result/enum.Result.html" title="enum std::result::Result">Result</a><<a class="primitive" href="../primitive.unit.html">()</a>, <a class="struct" href="../../std/fmt/struct.Error.html" title="struct std::fmt::Error">Error</a>></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/fmt/mod.rs.html#1188-1226' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>This function takes a string slice and emits it to the internal buffer after applying the relevant formatting flags specified. The flags recognized for generic strings are:</p> <ul> <li>width - the minimum width of what to emit</li> <li>fill/align - what to emit and where to emit it if the string provided needs to be padded</li> <li>precision - the maximum length to emit, the string is truncated if it is longer than this length</li> </ul> <p>Notably this function ignores the <code>flag</code> parameters.</p> </div><h4 id='method.write_str' class="method"><span id='write_str.v' class='invisible'><code>pub fn <a href='#method.write_str' class='fnname'>write_str</a>(&mut self, data: &<a class="primitive" href="../primitive.str.html">str</a>) -> <a class="enum" href="../../std/result/enum.Result.html" title="enum std::result::Result">Result</a><<a class="primitive" href="../primitive.unit.html">()</a>, <a class="struct" href="../../std/fmt/struct.Error.html" title="struct std::fmt::Error">Error</a>></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/fmt/mod.rs.html#1345-1347' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Writes some data to the underlying buffer contained within this formatter.</p> </div><h4 id='method.write_fmt' class="method"><span id='write_fmt.v' class='invisible'><code>pub fn <a href='#method.write_fmt' class='fnname'>write_fmt</a>(&mut self, fmt: <a class="struct" href="../../std/fmt/struct.Arguments.html" title="struct std::fmt::Arguments">Arguments</a>) -> <a class="enum" href="../../std/result/enum.Result.html" title="enum std::result::Result">Result</a><<a class="primitive" href="../primitive.unit.html">()</a>, <a class="struct" href="../../std/fmt/struct.Error.html" title="struct std::fmt::Error">Error</a>></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/fmt/mod.rs.html#1351-1353' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Writes some formatted information into this instance</p> </div><h4 id='method.flags' class="method"><span id='flags.v' class='invisible'><code>pub fn <a href='#method.flags' class='fnname'>flags</a>(&self) -> <a class="primitive" href="../primitive.u32.html">u32</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/fmt/mod.rs.html#1360' title='goto source code'>[src]</a></span></h4> <div class='stability'><div class='stab deprecated'>Deprecated since 1.24.0<p>: use the <code>sign_plus</code>, <code>sign_minus</code>, <code>alternate</code>, or <code>sign_aware_zero_pad</code> methods instead</p> </div></div><div class='docblock'><p>Flags for formatting</p> </div><h4 id='method.fill' class="method"><span id='fill.v' class='invisible'><code>pub fn <a href='#method.fill' class='fnname'>fill</a>(&self) -> <a class="primitive" href="../primitive.char.html">char</a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.5.0'>1.5.0</div><a class='srclink' href='../../src/core/fmt/mod.rs.html#1364' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Character used as 'fill' whenever there is alignment</p> </div><h4 id='method.align' class="method"><span id='align.v' class='invisible'><code>pub fn <a href='#method.align' class='fnname'>align</a>(&self) -> <a class="enum" href="../../core/fmt/enum.Alignment.html" title="enum core::fmt::Alignment">Alignment</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/fmt/mod.rs.html#1369-1376' title='goto source code'>[src]</a></span></h4> <div class='stability'><div class='stab unstable'><details><summary><span class=microscope>🔬</span> This is a nightly-only experimental API. (<code>fmt_flags_align </code><a href="https://github.com/rust-lang/rust/issues/27726">#27726</a>)</summary><p>method was just created</p> </details></div></div><div class='docblock'><p>Flag indicating what form of alignment was requested</p> </div><h4 id='method.width' class="method"><span id='width.v' class='invisible'><code>pub fn <a href='#method.width' class='fnname'>width</a>(&self) -> <a class="enum" href="../../std/option/enum.Option.html" title="enum std::option::Option">Option</a><<a class="primitive" href="../primitive.usize.html">usize</a>></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.5.0'>1.5.0</div><a class='srclink' href='../../src/core/fmt/mod.rs.html#1380' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Optionally specified integer width that the output should be</p> </div><h4 id='method.precision' class="method"><span id='precision.v' class='invisible'><code>pub fn <a href='#method.precision' class='fnname'>precision</a>(&self) -> <a class="enum" href="../../std/option/enum.Option.html" title="enum std::option::Option">Option</a><<a class="primitive" href="../primitive.usize.html">usize</a>></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.5.0'>1.5.0</div><a class='srclink' href='../../src/core/fmt/mod.rs.html#1384' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Optionally specified precision for numeric types</p> </div><h4 id='method.sign_plus' class="method"><span id='sign_plus.v' class='invisible'><code>pub fn <a href='#method.sign_plus' class='fnname'>sign_plus</a>(&self) -> <a class="primitive" href="../primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.5.0'>1.5.0</div><a class='srclink' href='../../src/core/fmt/mod.rs.html#1388' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Determines if the <code>+</code> flag was specified.</p> </div><h4 id='method.sign_minus' class="method"><span id='sign_minus.v' class='invisible'><code>pub fn <a href='#method.sign_minus' class='fnname'>sign_minus</a>(&self) -> <a class="primitive" href="../primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.5.0'>1.5.0</div><a class='srclink' href='../../src/core/fmt/mod.rs.html#1392' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Determines if the <code>-</code> flag was specified.</p> </div><h4 id='method.alternate' class="method"><span id='alternate.v' class='invisible'><code>pub fn <a href='#method.alternate' class='fnname'>alternate</a>(&self) -> <a class="primitive" href="../primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.5.0'>1.5.0</div><a class='srclink' href='../../src/core/fmt/mod.rs.html#1396' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Determines if the <code>#</code> flag was specified.</p> </div><h4 id='method.sign_aware_zero_pad' class="method"><span id='sign_aware_zero_pad.v' class='invisible'><code>pub fn <a href='#method.sign_aware_zero_pad' class='fnname'>sign_aware_zero_pad</a>(&self) -> <a class="primitive" href="../primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.5.0'>1.5.0</div><a class='srclink' href='../../src/core/fmt/mod.rs.html#1400-1402' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Determines if the <code>0</code> flag was specified.</p> </div><h4 id='method.debug_struct' class="method"><span id='debug_struct.v' class='invisible'><code>pub fn <a href='#method.debug_struct' class='fnname'>debug_struct</a>(&'b mut self, name: &<a class="primitive" href="../primitive.str.html">str</a>) -> <a class="struct" href="../../std/fmt/struct.DebugStruct.html" title="struct std::fmt::DebugStruct">DebugStruct</a><'b, 'a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.2.0'>1.2.0</div><a class='srclink' href='../../src/core/fmt/mod.rs.html#1433-1435' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Creates a <a href="../../std/fmt/struct.DebugStruct.html"><code>DebugStruct</code></a> builder designed to assist with creation of <a href="../../std/fmt/trait.Debug.html"><code>fmt::Debug</code></a> implementations for structs.</p> <h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1> <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">Foo</span> { <span class="ident">bar</span>: <span class="ident">i32</span>, <span class="ident">baz</span>: <span class="ident">String</span>, } <span class="kw">impl</span> <span class="ident">fmt</span>::<span class="ident">Debug</span> <span class="kw">for</span> <span class="ident">Foo</span> { <span class="kw">fn</span> <span class="ident">fmt</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">fmt</span>: <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">fmt</span>::<span class="ident">Formatter</span>) <span class="op">-></span> <span class="ident">fmt</span>::<span class="prelude-ty">Result</span> { <span class="ident">fmt</span>.<span class="ident">debug_struct</span>(<span class="string">"Foo"</span>) .<span class="ident">field</span>(<span class="string">"bar"</span>, <span class="kw-2">&</span><span class="self">self</span>.<span class="ident">bar</span>) .<span class="ident">field</span>(<span class="string">"baz"</span>, <span class="kw-2">&</span><span class="self">self</span>.<span class="ident">baz</span>) .<span class="ident">finish</span>() } } <span class="comment">// prints "Foo { bar: 10, baz: "Hello World" }"</span> <span class="macro">println</span><span class="macro">!</span>(<span class="string">"{:?}"</span>, <span class="ident">Foo</span> { <span class="ident">bar</span>: <span class="number">10</span>, <span class="ident">baz</span>: <span class="string">"Hello World"</span>.<span class="ident">to_string</span>() });<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Afmt%3B%0A%0Astruct%20Foo%20%7B%0A%20%20%20%20bar%3A%20i32%2C%0A%20%20%20%20baz%3A%20String%2C%0A%7D%0A%0Aimpl%20fmt%3A%3ADebug%20for%20Foo%20%7B%0A%20%20%20%20fn%20fmt(%26self%2C%20fmt%3A%20%26mut%20fmt%3A%3AFormatter)%20-%3E%20fmt%3A%3AResult%20%7B%0A%20%20%20%20%20%20%20%20fmt.debug_struct(%22Foo%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20.field(%22bar%22%2C%20%26self.bar)%0A%20%20%20%20%20%20%20%20%20%20%20%20.field(%22baz%22%2C%20%26self.baz)%0A%20%20%20%20%20%20%20%20%20%20%20%20.finish()%0A%20%20%20%20%7D%0A%7D%0A%0A%2F%2F%20prints%20%22Foo%20%7B%20bar%3A%2010%2C%20baz%3A%20%22Hello%20World%22%20%7D%22%0Aprintln!(%22%7B%3A%3F%7D%22%2C%20Foo%20%7B%20bar%3A%2010%2C%20baz%3A%20%22Hello%20World%22.to_string()%20%7D)%3B%0A%7D">Run</a></pre> </div><h4 id='method.debug_tuple' class="method"><span id='debug_tuple.v' class='invisible'><code>pub fn <a href='#method.debug_tuple' class='fnname'>debug_tuple</a>(&'b mut self, name: &<a class="primitive" href="../primitive.str.html">str</a>) -> <a class="struct" href="../../std/fmt/struct.DebugTuple.html" title="struct std::fmt::DebugTuple">DebugTuple</a><'b, 'a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.2.0'>1.2.0</div><a class='srclink' href='../../src/core/fmt/mod.rs.html#1460-1462' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Creates a <code>DebugTuple</code> builder designed to assist with creation of <code>fmt::Debug</code> implementations for tuple structs.</p> <h1 id="examples-1" class="section-header"><a href="#examples-1">Examples</a></h1> <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">Foo</span>(<span class="ident">i32</span>, <span class="ident">String</span>); <span class="kw">impl</span> <span class="ident">fmt</span>::<span class="ident">Debug</span> <span class="kw">for</span> <span class="ident">Foo</span> { <span class="kw">fn</span> <span class="ident">fmt</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">fmt</span>: <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">fmt</span>::<span class="ident">Formatter</span>) <span class="op">-></span> <span class="ident">fmt</span>::<span class="prelude-ty">Result</span> { <span class="ident">fmt</span>.<span class="ident">debug_tuple</span>(<span class="string">"Foo"</span>) .<span class="ident">field</span>(<span class="kw-2">&</span><span class="self">self</span>.<span class="number">0</span>) .<span class="ident">field</span>(<span class="kw-2">&</span><span class="self">self</span>.<span class="number">1</span>) .<span class="ident">finish</span>() } } <span class="comment">// prints "Foo(10, "Hello World")"</span> <span class="macro">println</span><span class="macro">!</span>(<span class="string">"{:?}"</span>, <span class="ident">Foo</span>(<span class="number">10</span>, <span class="string">"Hello World"</span>.<span class="ident">to_string</span>()));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Afmt%3B%0A%0Astruct%20Foo(i32%2C%20String)%3B%0A%0Aimpl%20fmt%3A%3ADebug%20for%20Foo%20%7B%0A%20%20%20%20fn%20fmt(%26self%2C%20fmt%3A%20%26mut%20fmt%3A%3AFormatter)%20-%3E%20fmt%3A%3AResult%20%7B%0A%20%20%20%20%20%20%20%20fmt.debug_tuple(%22Foo%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20.field(%26self.0)%0A%20%20%20%20%20%20%20%20%20%20%20%20.field(%26self.1)%0A%20%20%20%20%20%20%20%20%20%20%20%20.finish()%0A%20%20%20%20%7D%0A%7D%0A%0A%2F%2F%20prints%20%22Foo(10%2C%20%22Hello%20World%22)%22%0Aprintln!(%22%7B%3A%3F%7D%22%2C%20Foo(10%2C%20%22Hello%20World%22.to_string()))%3B%0A%7D">Run</a></pre> </div><h4 id='method.debug_list' class="method"><span id='debug_list.v' class='invisible'><code>pub fn <a href='#method.debug_list' class='fnname'>debug_list</a>(&'b mut self) -> <a class="struct" href="../../std/fmt/struct.DebugList.html" title="struct std::fmt::DebugList">DebugList</a><'b, 'a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.2.0'>1.2.0</div><a class='srclink' href='../../src/core/fmt/mod.rs.html#1484-1486' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Creates a <code>DebugList</code> builder designed to assist with creation of <code>fmt::Debug</code> implementations for list-like structures.</p> <h1 id="examples-2" class="section-header"><a href="#examples-2">Examples</a></h1> <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">Foo</span>(<span class="ident">Vec</span><span class="op"><</span><span class="ident">i32</span><span class="op">></span>); <span class="kw">impl</span> <span class="ident">fmt</span>::<span class="ident">Debug</span> <span class="kw">for</span> <span class="ident">Foo</span> { <span class="kw">fn</span> <span class="ident">fmt</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">fmt</span>: <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">fmt</span>::<span class="ident">Formatter</span>) <span class="op">-></span> <span class="ident">fmt</span>::<span class="prelude-ty">Result</span> { <span class="ident">fmt</span>.<span class="ident">debug_list</span>().<span class="ident">entries</span>(<span class="self">self</span>.<span class="number">0</span>.<span class="ident">iter</span>()).<span class="ident">finish</span>() } } <span class="comment">// prints "[10, 11]"</span> <span class="macro">println</span><span class="macro">!</span>(<span class="string">"{:?}"</span>, <span class="ident">Foo</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="number">10</span>, <span class="number">11</span>]));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Afmt%3B%0A%0Astruct%20Foo(Vec%3Ci32%3E)%3B%0A%0Aimpl%20fmt%3A%3ADebug%20for%20Foo%20%7B%0A%20%20%20%20fn%20fmt(%26self%2C%20fmt%3A%20%26mut%20fmt%3A%3AFormatter)%20-%3E%20fmt%3A%3AResult%20%7B%0A%20%20%20%20%20%20%20%20fmt.debug_list().entries(self.0.iter()).finish()%0A%20%20%20%20%7D%0A%7D%0A%0A%2F%2F%20prints%20%22%5B10%2C%2011%5D%22%0Aprintln!(%22%7B%3A%3F%7D%22%2C%20Foo(vec!%5B10%2C%2011%5D))%3B%0A%7D">Run</a></pre> </div><h4 id='method.debug_set' class="method"><span id='debug_set.v' class='invisible'><code>pub fn <a href='#method.debug_set' class='fnname'>debug_set</a>(&'b mut self) -> <a class="struct" href="../../std/fmt/struct.DebugSet.html" title="struct std::fmt::DebugSet">DebugSet</a><'b, 'a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.2.0'>1.2.0</div><a class='srclink' href='../../src/core/fmt/mod.rs.html#1508-1510' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Creates a <code>DebugSet</code> builder designed to assist with creation of <code>fmt::Debug</code> implementations for set-like structures.</p> <h1 id="examples-3" class="section-header"><a href="#examples-3">Examples</a></h1> <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">Foo</span>(<span class="ident">Vec</span><span class="op"><</span><span class="ident">i32</span><span class="op">></span>); <span class="kw">impl</span> <span class="ident">fmt</span>::<span class="ident">Debug</span> <span class="kw">for</span> <span class="ident">Foo</span> { <span class="kw">fn</span> <span class="ident">fmt</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">fmt</span>: <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">fmt</span>::<span class="ident">Formatter</span>) <span class="op">-></span> <span class="ident">fmt</span>::<span class="prelude-ty">Result</span> { <span class="ident">fmt</span>.<span class="ident">debug_set</span>().<span class="ident">entries</span>(<span class="self">self</span>.<span class="number">0</span>.<span class="ident">iter</span>()).<span class="ident">finish</span>() } } <span class="comment">// prints "{10, 11}"</span> <span class="macro">println</span><span class="macro">!</span>(<span class="string">"{:?}"</span>, <span class="ident">Foo</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="number">10</span>, <span class="number">11</span>]));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Afmt%3B%0A%0Astruct%20Foo(Vec%3Ci32%3E)%3B%0A%0Aimpl%20fmt%3A%3ADebug%20for%20Foo%20%7B%0A%20%20%20%20fn%20fmt(%26self%2C%20fmt%3A%20%26mut%20fmt%3A%3AFormatter)%20-%3E%20fmt%3A%3AResult%20%7B%0A%20%20%20%20%20%20%20%20fmt.debug_set().entries(self.0.iter()).finish()%0A%20%20%20%20%7D%0A%7D%0A%0A%2F%2F%20prints%20%22%7B10%2C%2011%7D%22%0Aprintln!(%22%7B%3A%3F%7D%22%2C%20Foo(vec!%5B10%2C%2011%5D))%3B%0A%7D">Run</a></pre> </div><h4 id='method.debug_map' class="method"><span id='debug_map.v' class='invisible'><code>pub fn <a href='#method.debug_map' class='fnname'>debug_map</a>(&'b mut self) -> <a class="struct" href="../../std/fmt/struct.DebugMap.html" title="struct std::fmt::DebugMap">DebugMap</a><'b, 'a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.2.0'>1.2.0</div><a class='srclink' href='../../src/core/fmt/mod.rs.html#1532-1534' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Creates a <code>DebugMap</code> builder designed to assist with creation of <code>fmt::Debug</code> implementations for map-like structures.</p> <h1 id="examples-4" class="section-header"><a href="#examples-4">Examples</a></h1> <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">Foo</span>(<span class="ident">Vec</span><span class="op"><</span>(<span class="ident">String</span>, <span class="ident">i32</span>)<span class="op">></span>); <span class="kw">impl</span> <span class="ident">fmt</span>::<span class="ident">Debug</span> <span class="kw">for</span> <span class="ident">Foo</span> { <span class="kw">fn</span> <span class="ident">fmt</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">fmt</span>: <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">fmt</span>::<span class="ident">Formatter</span>) <span class="op">-></span> <span class="ident">fmt</span>::<span class="prelude-ty">Result</span> { <span class="ident">fmt</span>.<span class="ident">debug_map</span>().<span class="ident">entries</span>(<span class="self">self</span>.<span class="number">0</span>.<span class="ident">iter</span>().<span class="ident">map</span>(<span class="op">|</span><span class="kw-2">&</span>(<span class="kw-2">ref</span> <span class="ident">k</span>, <span class="kw-2">ref</span> <span class="ident">v</span>)<span class="op">|</span> (<span class="ident">k</span>, <span class="ident">v</span>))).<span class="ident">finish</span>() } } <span class="comment">// prints "{"A": 10, "B": 11}"</span> <span class="macro">println</span><span class="macro">!</span>(<span class="string">"{:?}"</span>, <span class="ident">Foo</span>(<span class="macro">vec</span><span class="macro">!</span>[(<span class="string">"A"</span>.<span class="ident">to_string</span>(), <span class="number">10</span>), (<span class="string">"B"</span>.<span class="ident">to_string</span>(), <span class="number">11</span>)]));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Afmt%3B%0A%0Astruct%20Foo(Vec%3C(String%2C%20i32)%3E)%3B%0A%0Aimpl%20fmt%3A%3ADebug%20for%20Foo%20%7B%0A%20%20%20%20fn%20fmt(%26self%2C%20fmt%3A%20%26mut%20fmt%3A%3AFormatter)%20-%3E%20fmt%3A%3AResult%20%7B%0A%20%20%20%20%20%20%20%20fmt.debug_map().entries(self.0.iter().map(%7C%26(ref%20k%2C%20ref%20v)%7C%20(k%2C%20v))).finish()%0A%20%20%20%20%7D%0A%7D%0A%0A%2F%2F%20prints%20%22%7B%22A%22%3A%2010%2C%20%22B%22%3A%2011%7D%22%0Aprintln!(%22%7B%3A%3F%7D%22%2C%20Foo(vec!%5B(%22A%22.to_string()%2C%2010)%2C%20(%22B%22.to_string()%2C%2011)%5D))%3B%0A%7D">Run</a></pre> </div></div> <h2 id='implementations' class='small-section-header'> Trait Implementations<a href='#implementations' class='anchor'></a> </h2> <h3 id='impl-Write' class='impl'><span class='in-band'><code>impl<'a> <a class="trait" href="../../std/fmt/trait.Write.html" title="trait std::fmt::Write">Write</a> for <a class="struct" href="../../std/fmt/struct.Formatter.html" title="struct std::fmt::Formatter">Formatter</a><'a></code><a href='#impl-Write' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.2.0'>1.2.0</div><a class='srclink' href='../../src/core/fmt/mod.rs.html#1538-1550' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.write_str-1' class="method"><span id='write_str.v-1' class='invisible'><code>fn <a href='../../std/fmt/trait.Write.html#tymethod.write_str' class='fnname'>write_str</a>(&mut self, s: &<a class="primitive" href="../primitive.str.html">str</a>) -> <a class="enum" href="../../std/result/enum.Result.html" title="enum std::result::Result">Result</a><<a class="primitive" href="../primitive.unit.html">()</a>, <a class="struct" href="../../std/fmt/struct.Error.html" title="struct std::fmt::Error">Error</a>></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/fmt/mod.rs.html#1539-1541' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Writes a slice of bytes into this writer, returning whether the write succeeded. <a href="../../std/fmt/trait.Write.html#tymethod.write_str">Read more</a></p> </div><h4 id='method.write_char' class="method"><span id='write_char.v' class='invisible'><code>fn <a href='../../std/fmt/trait.Write.html#method.write_char' class='fnname'>write_char</a>(&mut self, c: <a class="primitive" href="../primitive.char.html">char</a>) -> <a class="enum" href="../../std/result/enum.Result.html" title="enum std::result::Result">Result</a><<a class="primitive" href="../primitive.unit.html">()</a>, <a class="struct" href="../../std/fmt/struct.Error.html" title="struct std::fmt::Error">Error</a>></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/fmt/mod.rs.html#1543-1545' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Writes a [<code>char</code>] into this writer, returning whether the write succeeded. <a href="../../std/fmt/trait.Write.html#method.write_char">Read more</a></p> </div><h4 id='method.write_fmt-1' class="method"><span id='write_fmt.v-1' class='invisible'><code>fn <a href='../../std/fmt/trait.Write.html#method.write_fmt' class='fnname'>write_fmt</a>(&mut self, args: <a class="struct" href="../../std/fmt/struct.Arguments.html" title="struct std::fmt::Arguments">Arguments</a>) -> <a class="enum" href="../../std/result/enum.Result.html" title="enum std::result::Result">Result</a><<a class="primitive" href="../primitive.unit.html">()</a>, <a class="struct" href="../../std/fmt/struct.Error.html" title="struct std::fmt::Error">Error</a>></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/fmt/mod.rs.html#1547-1549' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Glue for usage of the [<code>write!</code>] macro with implementors of this trait. <a href="../../std/fmt/trait.Write.html#method.write_fmt">Read more</a></p> </div></div></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><kbd>?</kbd></dt> <dd>Show this help dialog</dd> <dt><kbd>S</kbd></dt> <dd>Focus the search field</dd> <dt><kbd>↑</kbd></dt> <dd>Move up in search results</dd> <dt><kbd>↓</kbd></dt> <dd>Move down in search results</dd> <dt><kbd>↹</kbd></dt> <dd>Switch tab</dd> <dt><kbd>⏎</kbd></dt> <dd>Go to active search result</dd> <dt><kbd>+</kbd></dt> <dd>Expand all sections</dd> <dt><kbd>-</kbd></dt> <dd>Collapse all sections</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> or <code>* -> vec</code>) </p> </div> </div> </aside> <script> window.rootPath = "../../"; window.currentCrate = "std"; </script> <script src="../../main.js"></script> <script defer src="../../search-index.js"></script> </body> </html>