Sophie

Sophie

distrib > Mageia > 6 > armv7hl > media > core-updates > by-pkgid > 4e2dbb669434a7691662cb2f0ad38972 > files > 10066

rust-doc-1.28.0-1.mga6.armv7hl.rpm

<!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 `PanicInfo` struct in crate `core`."><meta name="keywords" content="rust, rustlang, rust-lang, PanicInfo"><title>core::panic::PanicInfo - 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="../../light.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">&#9776;</div><a href='../../core/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 PanicInfo</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#methods">Methods</a><div class="sidebar-links"><a href="#method.payload">payload</a><a href="#method.message">message</a><a href="#method.location">location</a></div><a class="sidebar-title" href="#implementations">Trait Implementations</a><div class="sidebar-links"><a href="#impl-Debug">Debug</a><a href="#impl-Display">Display</a></div><a class="sidebar-title" href="#synthetic-implementations">Auto Trait Implementations</a><div class="sidebar-links"><a href="#impl-Send">!Send</a><a href="#impl-Sync">!Sync</a></div></div><p class='location'><a href='../index.html'>core</a>::<wbr><a href='index.html'>panic</a></p><script>window.sidebarCurrent = {name: 'PanicInfo', 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"><a id="settings-menu" href="../../settings.html"><img src="../../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class='fqn'><span class='in-band'>Struct <a href='../index.html'>core</a>::<wbr><a href='index.html'>panic</a>::<wbr><a class="struct" href=''>PanicInfo</a></span><span class='out-of-band'><span class='since' title='Stable since Rust version 1.10.0'>1.10.0</span><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 class='srclink' href='../../src/core/panic.rs.html#41-45' title='goto source code'>[src]</a></span></h1><div class="docblock type-decl"><pre class='rust struct'><div class="docblock attributes">#[lang = "panic_info"]
</div>pub struct PanicInfo&lt;'a&gt; { /* fields omitted */ }</pre></div><div class='docblock'><p>A struct providing information about a panic.</p>
<p><code>PanicInfo</code> structure is passed to a panic hook set by the <a href="../../std/panic/fn.set_hook.html"><code>set_hook</code></a>
function.</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">panic</span>;

<span class="ident">panic</span>::<span class="ident">set_hook</span>(<span class="ident">Box</span>::<span class="ident">new</span>(<span class="op">|</span><span class="ident">panic_info</span><span class="op">|</span> {
    <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;panic occurred: {:?}&quot;</span>, <span class="ident">panic_info</span>.<span class="ident">payload</span>().<span class="ident">downcast_ref</span>::<span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span>().<span class="ident">unwrap</span>());
}));

<span class="macro">panic</span><span class="macro">!</span>(<span class="string">&quot;Normal panic&quot;</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%3Apanic%3B%0A%0Apanic%3A%3Aset_hook(Box%3A%3Anew(%7Cpanic_info%7C%20%7B%0A%20%20%20%20println!(%22panic%20occurred%3A%20%7B%3A%3F%7D%22%2C%20panic_info.payload().downcast_ref%3A%3A%3C%26str%3E().unwrap())%3B%0A%7D))%3B%0A%0Apanic!(%22Normal%20panic%22)%3B%0A%7D">Run</a></pre>
</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'><table class='table-display'><tbody><tr><td><code>impl&lt;'a&gt; <a class="struct" href="../../core/panic/struct.PanicInfo.html" title="struct core::panic::PanicInfo">PanicInfo</a>&lt;'a&gt;</code><a href='#impl' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/panic.rs.html#47-129' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.payload' class="method"><span id='payload.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.payload' class='fnname'>payload</a>(&amp;self) -&gt; &amp;(<a class="trait" href="../../core/any/trait.Any.html" title="trait core::any::Any">Any</a> + <a class="trait" href="../../core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>)</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/panic.rs.html#85-87' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Returns the payload associated with the panic.</p>
<p>This will commonly, but not always, be a <code>&amp;'static str</code> or <a href="../../std/string/struct.String.html"><code>String</code></a>.</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">panic</span>;

<span class="ident">panic</span>::<span class="ident">set_hook</span>(<span class="ident">Box</span>::<span class="ident">new</span>(<span class="op">|</span><span class="ident">panic_info</span><span class="op">|</span> {
    <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;panic occurred: {:?}&quot;</span>, <span class="ident">panic_info</span>.<span class="ident">payload</span>().<span class="ident">downcast_ref</span>::<span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span><span class="op">&gt;</span>().<span class="ident">unwrap</span>());
}));

<span class="macro">panic</span><span class="macro">!</span>(<span class="string">&quot;Normal panic&quot;</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%3Apanic%3B%0A%0Apanic%3A%3Aset_hook(Box%3A%3Anew(%7Cpanic_info%7C%20%7B%0A%20%20%20%20println!(%22panic%20occurred%3A%20%7B%3A%3F%7D%22%2C%20panic_info.payload().downcast_ref%3A%3A%3C%26str%3E().unwrap())%3B%0A%7D))%3B%0A%0Apanic!(%22Normal%20panic%22)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.message' class="method"><span id='message.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.message' class='fnname'>message</a>(&amp;self) -&gt; <a class="enum" href="../../core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;&amp;<a class="struct" href="../../core/fmt/struct.Arguments.html" title="struct core::fmt::Arguments">Arguments</a>&gt;</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/panic.rs.html#95-97' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>panic_info_message </code><a href="https://github.com/rust-lang/rust/issues/44489">#44489</a>)</div></div><div class='docblock'><p>If the <code>panic!</code> macro from the <code>core</code> crate (not from <code>std</code>)
was used with a formatting string and some additional arguments,
returns that message ready to be used for example with <a href="../fmt/fn.write.html"><code>fmt::write</code></a></p>
</div><h4 id='method.location' class="method"><span id='location.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.location' class='fnname'>location</a>(&amp;self) -&gt; <a class="enum" href="../../core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;&amp;<a class="struct" href="../../core/panic/struct.Location.html" title="struct core::panic::Location">Location</a>&gt;</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/panic.rs.html#124-128' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Returns information about the location from which the panic originated,
if available.</p>
<p>This method will currently always return <a href="../../std/option/enum.Option.html#variant.Some"><code>Some</code></a>, but this may change
in future versions.</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">panic</span>;

<span class="ident">panic</span>::<span class="ident">set_hook</span>(<span class="ident">Box</span>::<span class="ident">new</span>(<span class="op">|</span><span class="ident">panic_info</span><span class="op">|</span> {
    <span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">location</span>) <span class="op">=</span> <span class="ident">panic_info</span>.<span class="ident">location</span>() {
        <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;panic occurred in file &#39;{}&#39; at line {}&quot;</span>, <span class="ident">location</span>.<span class="ident">file</span>(),
            <span class="ident">location</span>.<span class="ident">line</span>());
    } <span class="kw">else</span> {
        <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;panic occurred but can&#39;t get location information...&quot;</span>);
    }
}));

<span class="macro">panic</span><span class="macro">!</span>(<span class="string">&quot;Normal panic&quot;</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%3Apanic%3B%0A%0Apanic%3A%3Aset_hook(Box%3A%3Anew(%7Cpanic_info%7C%20%7B%0A%20%20%20%20if%20let%20Some(location)%20%3D%20panic_info.location()%20%7B%0A%20%20%20%20%20%20%20%20println!(%22panic%20occurred%20in%20file%20'%7B%7D'%20at%20line%20%7B%7D%22%2C%20location.file()%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20location.line())%3B%0A%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20%20%20println!(%22panic%20occurred%20but%20can't%20get%20location%20information...%22)%3B%0A%20%20%20%20%7D%0A%7D))%3B%0A%0Apanic!(%22Normal%20panic%22)%3B%0A%7D">Run</a></pre>
</div></div>
                <h2 id='implementations' class='small-section-header'>
                  Trait Implementations<a href='#implementations' class='anchor'></a>
                </h2>
                <div id='implementations-list'><h3 id='impl-Debug' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl&lt;'a&gt; <a class="trait" href="../../core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="../../core/panic/struct.PanicInfo.html" title="struct core::panic::PanicInfo">PanicInfo</a>&lt;'a&gt;</code><a href='#impl-Debug' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/panic.rs.html#40' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.fmt' class="method"><span id='fmt.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/fmt/trait.Debug.html#tymethod.fmt' class='fnname'>fmt</a>(&amp;self, f: &amp;mut <a class="struct" href="../../core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>) -&gt; <a class="type" href="../../core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/panic.rs.html#40' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Formats the value using the given formatter. <a href="../../core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></p>
</div></div><h3 id='impl-Display' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl&lt;'a&gt; <a class="trait" href="../../core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a> for <a class="struct" href="../../core/panic/struct.PanicInfo.html" title="struct core::panic::PanicInfo">PanicInfo</a>&lt;'a&gt;</code><a href='#impl-Display' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.26.0'>1.26.0</div><a class='srclink' href='../../src/core/panic.rs.html#132-147' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.fmt-1' class="method"><span id='fmt.v-1' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../core/fmt/trait.Display.html#tymethod.fmt' class='fnname'>fmt</a>(&amp;self, formatter: &amp;mut <a class="struct" href="../../core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>) -&gt; <a class="type" href="../../core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/core/panic.rs.html#133-146' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Formats the value using the given formatter. <a href="../../core/fmt/trait.Display.html#tymethod.fmt">Read more</a></p>
</div></div></div>
                <h2 id='synthetic-implementations' class='small-section-header'>
                  Auto Trait Implementations<a href='#synthetic-implementations' class='anchor'></a>
                </h2>
                <div id='synthetic-implementations-list'>
            <h3 id='impl-Send' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl&lt;'a&gt; !<a class="trait" href="../../core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="../../core/panic/struct.PanicInfo.html" title="struct core::panic::PanicInfo">PanicInfo</a>&lt;'a&gt;</code><a href='#impl-Send' class='anchor'></a></span></td><td><span class='out-of-band'></span></td></tr></tbody></table></h3><div class='impl-items'></div><h3 id='impl-Sync' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl&lt;'a&gt; !<a class="trait" href="../../core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="../../core/panic/struct.PanicInfo.html" title="struct core::panic::PanicInfo">PanicInfo</a>&lt;'a&gt;</code><a href='#impl-Sync' class='anchor'></a></span></td><td><span class='out-of-band'></span></td></tr></tbody></table></h3><div class='impl-items'></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>&#9166;</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><p>Search multiple things at once by splitting your query with comma (e.g. <code>str,u8</code> or <code>String,struct:Vec,test</code>)</p></div></div></aside><script>window.rootPath = "../../";window.currentCrate = "core";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>