Files
mercator_service/nom/lib/std/ops/trait.Fn.html

43 lines
13 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!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 `Fn` trait in crate `nom`."><meta name="keywords" content="rust, rustlang, rust-lang, Fn"><title>nom::lib::std::ops::Fn - 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><noscript><link rel="stylesheet" href="../../../../noscript.css"></noscript><link rel="shortcut icon" href="../../../../favicon.ico"><style type="text/css">#crate-search{background-image:url("../../../../down-arrow.svg");}</style></head><body class="rustdoc trait"><!--[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='../../../../nom/index.html'><div class='logo-container'><img src='../../../../rust-logo.png' alt='logo'></div></a><p class='location'>Trait Fn</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#required-methods">Required Methods</a><div class="sidebar-links"><a href="#tymethod.call">call</a></div><a class="sidebar-title" href="#foreign-impls">Implementations on Foreign Types</a><div class="sidebar-links"><a href="#impl-Fn%3CA%3E-for-%26%27_%20F">&amp;&#39;_ F</a></div><a class="sidebar-title" href="#implementors">Implementors</a></div><p class='location'><a href='../../../index.html'>nom</a>::<wbr><a href='../../index.html'>lib</a>::<wbr><a href='../index.html'>std</a>::<wbr><a href='index.html'>ops</a></p><script>window.sidebarCurrent = {name: 'Fn', ty: 'trait', 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"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><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='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'>&#x2212;</span>]</a></span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/ops/function.rs.html#69-73' title='goto source code'>[src]</a></span><span class='in-band'>Trait <a href='../../../index.html'>nom</a>::<wbr><a href='../../index.html'>lib</a>::<wbr><a href='../index.html'>std</a>::<wbr><a href='index.html'>ops</a>::<wbr><a class="trait" href=''>Fn</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class='rust trait'><span class="docblock attributes top-attr">#[lang = "fn"]
#[must_use = "closures are lazy and do nothing unless called"]
</span>pub trait Fn&lt;Args&gt;: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.FnMut.html" title="trait nom::lib::std::prelude::v1::v1::FnMut">FnMut</a>&lt;Args&gt; {
extern &quot;rust-call&quot; fn <a href='#tymethod.call' class='fnname'>call</a>(&amp;self, args: Args) -&gt; Self::<a class="type" href="../../../../nom/lib/std/prelude/v1/v1/trait.FnOnce.html#associatedtype.Output" title="type nom::lib::std::prelude::v1::v1::FnOnce::Output">Output</a>;
}</pre></div><div class='docblock'><p>The version of the call operator that takes an immutable receiver.</p>
<p>Instances of <code>Fn</code> can be called repeatedly without mutating state.</p>
<p><em>This trait (<code>Fn</code>) is not to be confused with <a href="../../std/primitive.fn.html">function pointers</a>
(<code>fn</code>).</em></p>
<p><code>Fn</code> is implemented automatically by closures which only take immutable
references to captured variables or don't capture anything at all, as well
as (safe) <a href="../../std/primitive.fn.html">function pointers</a> (with some caveats, see their documentation
for more details). Additionally, for any type <code>F</code> that implements <code>Fn</code>, <code>&amp;F</code>
implements <code>Fn</code>, too.</p>
<p>Since both <a href="trait.FnMut.html"><code>FnMut</code></a> and <a href="trait.FnOnce.html"><code>FnOnce</code></a> are supertraits of <code>Fn</code>, any
instance of <code>Fn</code> can be used as a parameter where a <a href="trait.FnMut.html"><code>FnMut</code></a> or <a href="trait.FnOnce.html"><code>FnOnce</code></a>
is expected.</p>
<p>Use <code>Fn</code> as a bound when you want to accept a parameter of function-like
type and need to call it repeatedly and without mutating state (e.g., when
calling it concurrently). If you do not need such strict requirements, use
<a href="trait.FnMut.html"><code>FnMut</code></a> or <a href="trait.FnOnce.html"><code>FnOnce</code></a> as bounds.</p>
<p>See the <a href="../../book/ch13-01-closures.html">chapter on closures in <em>The Rust Programming Language</em></a> for
some more information on this topic.</p>
<p>Also of note is the special syntax for <code>Fn</code> traits (e.g.
<code>Fn(usize, bool) -&gt; usize</code>). Those interested in the technical details of
this can refer to <a href="../../nomicon/hrtb.html">the relevant section in the <em>Rustonomicon</em></a>.</p>
<h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1><h2 id="calling-a-closure" class="section-header"><a href="#calling-a-closure">Calling a closure</a></h2>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">square</span> <span class="op">=</span> <span class="op">|</span><span class="ident">x</span><span class="op">|</span> <span class="ident">x</span> <span class="op">*</span> <span class="ident">x</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">square</span>(<span class="number">5</span>), <span class="number">25</span>);</pre></div>
<h2 id="using-a-fn-parameter" class="section-header"><a href="#using-a-fn-parameter">Using a <code>Fn</code> parameter</a></h2>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">fn</span> <span class="ident">call_with_one</span><span class="op">&lt;</span><span class="ident">F</span><span class="op">&gt;</span>(<span class="ident">func</span>: <span class="ident">F</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="ident">usize</span>
<span class="kw">where</span> <span class="ident">F</span>: <span class="ident">Fn</span>(<span class="ident">usize</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="ident">usize</span> {
<span class="ident">func</span>(<span class="number">1</span>)
}
<span class="kw">let</span> <span class="ident">double</span> <span class="op">=</span> <span class="op">|</span><span class="ident">x</span><span class="op">|</span> <span class="ident">x</span> <span class="op">*</span> <span class="number">2</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">call_with_one</span>(<span class="ident">double</span>), <span class="number">2</span>);</pre></div>
</div>
<h2 id='required-methods' class='small-section-header'>Required methods<a href='#required-methods' class='anchor'></a></h2><div class='methods'><h3 id='tymethod.call' class='method'><code id='call.v'>extern &quot;rust-call&quot; fn <a href='#tymethod.call' class='fnname'>call</a>(&amp;self, args: Args) -&gt; Self::<a class="type" href="../../../../nom/lib/std/prelude/v1/v1/trait.FnOnce.html#associatedtype.Output" title="type nom::lib::std::prelude::v1::v1::FnOnce::Output">Output</a></code></h3><div class='stability'><div class='stab unstable'><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>fn_traits</code>)</div></div><div class='docblock'><p>Performs the call operation.</p>
</div></div><span class='loading-content'>Loading content...</span>
<h2 id='foreign-impls' class='small-section-header'>Implementations on Foreign Types<a href='#foreign-impls' class='anchor'></a></h2><h3 id='impl-Fn%3CA%3E-for-%26%27_%20F' class='impl'><code class='in-band'>impl&lt;'_, A, F&gt; <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Fn.html" title="trait nom::lib::std::prelude::v1::v1::Fn">Fn</a>&lt;A&gt; for <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;'_ </a>F <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Fn.html" title="trait nom::lib::std::prelude::v1::v1::Fn">Fn</a>&lt;A&gt; + ?<a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Sized.html" title="trait nom::lib::std::prelude::v1::v1::Sized">Sized</a>,&nbsp;</span></code><a href='#impl-Fn%3CA%3E-for-%26%27_%20F' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/ops/function.rs.html#237-244' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.call' class="method hidden"><code id='call.v-1'>extern &quot;rust-call&quot; fn <a href='#method.call' class='fnname'>call</a>(&amp;self, args: A) -&gt; &lt;F as <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.FnOnce.html" title="trait nom::lib::std::prelude::v1::v1::FnOnce">FnOnce</a>&lt;A&gt;&gt;::<a class="type" href="../../../../nom/lib/std/prelude/v1/v1/trait.FnOnce.html#associatedtype.Output" title="type nom::lib::std::prelude::v1::v1::FnOnce::Output">Output</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/ops/function.rs.html#241-243' title='goto source code'>[src]</a></h4><div class='stability hidden'><div class='stab unstable'><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>fn_traits</code>)</div></div></div><span class='loading-content'>Loading content...</span>
<h2 id='implementors' class='small-section-header'>Implementors<a href='#implementors' class='anchor'></a></h2><div class='item-list' id='implementors-list'><h3 id='impl-Fn%3CA%3E' class='impl'><code class='in-band'>impl&lt;A, F&gt; Fn&lt;A&gt; for <a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Box.html" title="struct nom::lib::std::prelude::v1::v1::Box">Box</a>&lt;F&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Fn.html" title="trait nom::lib::std::prelude::v1::v1::Fn">Fn</a>&lt;A&gt; + ?<a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.Sized.html" title="trait nom::lib::std::prelude::v1::v1::Sized">Sized</a>,&nbsp;</span></code><a href='#impl-Fn%3CA%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/boxed.rs.html#1029-1033' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.call-1' class="method hidden"><code id='call.v-2'>extern &quot;rust-call&quot; fn <a href='#method.call-1' class='fnname'>call</a>(&amp;self, args: A) -&gt; &lt;<a class="struct" href="../../../../nom/lib/std/prelude/v1/v1/struct.Box.html" title="struct nom::lib::std::prelude::v1::v1::Box">Box</a>&lt;F&gt; as <a class="trait" href="../../../../nom/lib/std/prelude/v1/v1/trait.FnOnce.html" title="trait nom::lib::std::prelude::v1::v1::FnOnce">FnOnce</a>&lt;A&gt;&gt;::<a class="type" href="../../../../nom/lib/std/prelude/v1/v1/trait.FnOnce.html#associatedtype.Output" title="type nom::lib::std::prelude::v1::v1::FnOnce::Output">Output</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/alloc/boxed.rs.html#1030-1032' title='goto source code'>[src]</a></h4><div class='stability hidden'><div class='stab unstable'><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>fn_traits</code>)</div></div></div></div><span class='loading-content'>Loading content...</span><script type="text/javascript" src="../../../../implementors/core/ops/function/trait.Fn.js" async></script></section><section id="search" class="content hidden"></section><section class="footer"></section><script>window.rootPath = "../../../../";window.currentCrate = "nom";</script><script src="../../../../aliases.js"></script><script src="../../../../main.js"></script><script defer src="../../../../search-index.js"></script></body></html>