1
0
mirror of https://github.com/actix/actix-website synced 2024-11-28 10:32:38 +01:00
actix-website/static/api/actix-web/0.7.0/actix_web/dev/struct.Route.html
2018-07-21 04:09:47 -07:00

151 lines
34 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 `Route` struct in crate `actix_web`."><meta name="keywords" content="rust, rustlang, rust-lang, Route"><title>actix_web::dev::Route - 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></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><p class='location'>Struct Route</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#methods">Methods</a><div class="sidebar-links"><a href="#method.filter">filter</a><a href="#method.h">h</a><a href="#method.f">f</a><a href="#method.a">a</a><a href="#method.with">with</a><a href="#method.with_config">with_config</a><a href="#method.with_async">with_async</a><a href="#method.with_async_config">with_async_config</a></div><a class="sidebar-title" href="#implementations">Trait Implementations</a><div class="sidebar-links"><a href="#impl-Default">Default</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'>actix_web</a>::<wbr><a href='index.html'>dev</a></p><script>window.sidebarCurrent = {name: 'Route', 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'>actix_web</a>::<wbr><a href='index.html'>dev</a>::<wbr><a class="struct" href=''>Route</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 class='srclink' href='../../src/actix_web/route.rs.html#25-28' title='goto source code'>[src]</a></span></h1><div class="docblock type-decl"><pre class='rust struct'>pub struct Route&lt;S&gt; { /* fields omitted */ }</pre></div><div class='docblock'><p>Resource route definition</p>
<p>Route uses builder-like pattern for configuration.
If handler is not explicitly set, default <em>404 Not Found</em> handler is used.</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'><table class='table-display'><tbody><tr><td><code>impl&lt;S:&nbsp;'static&gt; <a class="struct" href="../../actix_web/dev/struct.Route.html" title="struct actix_web::dev::Route">Route</a>&lt;S&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/actix_web/route.rs.html#39-296' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.filter' class="method"><div class="important-traits"><div class='tooltip'><span class='tooltiptext'>Important traits for <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;'a mut </a>R</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;'a mut </a>R</h3><code class="content"><span class="where fmt-newline">impl&lt;'a, R&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/std/io/trait.Read.html" title="trait std::io::Read">Read</a> for <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;'a mut </a>R <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="https://doc.rust-lang.org/nightly/std/io/trait.Read.html" title="trait std::io::Read">Read</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></span><span class="where fmt-newline">impl&lt;'a, W&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/std/io/trait.Write.html" title="trait std::io::Write">Write</a> for <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;'a mut </a>W <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;W: <a class="trait" href="https://doc.rust-lang.org/nightly/std/io/trait.Write.html" title="trait std::io::Write">Write</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></span><span class="where fmt-newline">impl&lt;'a, I&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/iterator/trait.Iterator.html" title="trait core::iter::iterator::Iterator">Iterator</a> for <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;'a mut </a>I <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;I: <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/iterator/trait.Iterator.html" title="trait core::iter::iterator::Iterator">Iterator</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></span><span class="where fmt-newline"> type <a href='https://doc.rust-lang.org/nightly/core/iter/iterator/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = &lt;I as <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/iterator/trait.Iterator.html" title="trait core::iter::iterator::Iterator">Iterator</a>&gt;::<a class="type" href="https://doc.rust-lang.org/nightly/core/iter/iterator/trait.Iterator.html#associatedtype.Item" title="type core::iter::iterator::Iterator::Item">Item</a>;</span></code></div></div><span id='filter.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.filter' class='fnname'>filter</a>&lt;T:&nbsp;<a class="trait" href="../../actix_web/pred/trait.Predicate.html" title="trait actix_web::pred::Predicate">Predicate</a>&lt;S&gt; + 'static&gt;(&amp;mut self, p: T) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>Self</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/actix_web/route.rs.html#78-81' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Add match predicate to route.</p>
<pre class="rust rust-example-rendered">
<span class="ident">App</span>::<span class="ident">new</span>().<span class="ident">resource</span>(<span class="string">&quot;/path&quot;</span>, <span class="op">|</span><span class="ident">r</span><span class="op">|</span> {
<span class="ident">r</span>.<span class="ident">route</span>()
.<span class="ident">filter</span>(<span class="ident">pred</span>::<span class="ident">Get</span>())
.<span class="ident">filter</span>(<span class="ident">pred</span>::<span class="ident">Header</span>(<span class="string">&quot;content-type&quot;</span>, <span class="string">&quot;text/plain&quot;</span>))
.<span class="ident">f</span>(<span class="op">|</span><span class="ident">req</span><span class="op">|</span> <span class="ident">HttpResponse</span>::<span class="prelude-val">Ok</span>())
})</pre>
</div><h4 id='method.h' class="method"><span id='h.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.h' class='fnname'>h</a>&lt;H:&nbsp;<a class="trait" href="../../actix_web/dev/trait.Handler.html" title="trait actix_web::dev::Handler">Handler</a>&lt;S&gt;&gt;(&amp;mut self, handler: H)</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/actix_web/route.rs.html#85-87' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Set handler object. Usually call to this method is last call
during route configuration, so it does not return reference to self.</p>
</div><h4 id='method.f' class="method"><span id='f.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.f' class='fnname'>f</a>&lt;F, R&gt;(&amp;mut self, handler: F) <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&amp;<a class="struct" href="../../actix_web/struct.HttpRequest.html" title="struct actix_web::HttpRequest">HttpRequest</a>&lt;S&gt;) -&gt; R + 'static,<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../../actix_web/trait.Responder.html" title="trait actix_web::Responder">Responder</a> + 'static,&nbsp;</span></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/actix_web/route.rs.html#91-97' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Set handler function. Usually call to this method is last call
during route configuration, so it does not return reference to self.</p>
</div><h4 id='method.a' class="method"><span id='a.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.a' class='fnname'>a</a>&lt;H, R, F, E&gt;(&amp;mut self, handler: H) <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;H: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&amp;<a class="struct" href="../../actix_web/struct.HttpRequest.html" title="struct actix_web::HttpRequest">HttpRequest</a>&lt;S&gt;) -&gt; F + 'static,<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="https://docs.rs/futures/0.1/futures/future/trait.Future.html" title="trait futures::future::Future">Future</a>&lt;Item = R, Error = E&gt; + 'static,<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../../actix_web/trait.Responder.html" title="trait actix_web::Responder">Responder</a> + 'static,<br>&nbsp;&nbsp;&nbsp;&nbsp;E: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;<a class="struct" href="../../actix_web/error/struct.Error.html" title="struct actix_web::error::Error">Error</a>&gt; + 'static,&nbsp;</span></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/actix_web/route.rs.html#100-108' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Set async handler function.</p>
</div><h4 id='method.with' class="method"><span id='with.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.with' class='fnname'>with</a>&lt;T, F, R&gt;(&amp;mut self, handler: F) <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(T) -&gt; R + 'static,<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../../actix_web/trait.Responder.html" title="trait actix_web::Responder">Responder</a> + 'static,<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../actix_web/trait.FromRequest.html" title="trait actix_web::FromRequest">FromRequest</a>&lt;S&gt; + 'static,&nbsp;</span></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/actix_web/route.rs.html#167-174' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Set handler function, use request extractor for parameters.</p>
<pre class="rust rust-example-rendered">
<span class="attribute">#[<span class="ident">macro_use</span>]</span> <span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">serde_derive</span>;
<span class="kw">use</span> <span class="ident">actix_web</span>::{<span class="ident">http</span>, <span class="ident">App</span>, <span class="ident">Path</span>, <span class="prelude-ty">Result</span>};
<span class="attribute">#[<span class="ident">derive</span>(<span class="ident">Deserialize</span>)]</span>
<span class="kw">struct</span> <span class="ident">Info</span> {
<span class="ident">username</span>: <span class="ident">String</span>,
}
<span class="doccomment">/// extract path info using serde</span>
<span class="kw">fn</span> <span class="ident">index</span>(<span class="ident">info</span>: <span class="ident">Path</span><span class="op">&lt;</span><span class="ident">Info</span><span class="op">&gt;</span>) <span class="op">-&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="ident">String</span><span class="op">&gt;</span> {
<span class="prelude-val">Ok</span>(<span class="macro">format</span><span class="macro">!</span>(<span class="string">&quot;Welcome {}!&quot;</span>, <span class="ident">info</span>.<span class="ident">username</span>))
}
<span class="kw">fn</span> <span class="ident">main</span>() {
<span class="kw">let</span> <span class="ident">app</span> <span class="op">=</span> <span class="ident">App</span>::<span class="ident">new</span>().<span class="ident">resource</span>(
<span class="string">&quot;/{username}/index.html&quot;</span>, <span class="comment">// &lt;- define path parameters</span>
<span class="op">|</span><span class="ident">r</span><span class="op">|</span> <span class="ident">r</span>.<span class="ident">method</span>(<span class="ident">http</span>::<span class="ident">Method</span>::<span class="ident">GET</span>).<span class="ident">with</span>(<span class="ident">index</span>),
); <span class="comment">// &lt;- use `with` extractor</span>
}</pre>
<p>It is possible to use tuples for specifing multiple extractors for one
handler function.</p>
<pre class="rust rust-example-rendered">
<span class="attribute">#[<span class="ident">macro_use</span>]</span> <span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">serde_derive</span>;
<span class="kw">use</span> <span class="ident">actix_web</span>::{<span class="ident">http</span>, <span class="ident">App</span>, <span class="ident">Json</span>, <span class="ident">Path</span>, <span class="ident">Query</span>, <span class="prelude-ty">Result</span>};
<span class="attribute">#[<span class="ident">derive</span>(<span class="ident">Deserialize</span>)]</span>
<span class="kw">struct</span> <span class="ident">Info</span> {
<span class="ident">username</span>: <span class="ident">String</span>,
}
<span class="doccomment">/// extract path info using serde</span>
<span class="kw">fn</span> <span class="ident">index</span>(
<span class="ident">info</span>: (<span class="ident">Path</span><span class="op">&lt;</span><span class="ident">Info</span><span class="op">&gt;</span>, <span class="ident">Query</span><span class="op">&lt;</span><span class="ident">HashMap</span><span class="op">&lt;</span><span class="ident">String</span>, <span class="ident">String</span><span class="op">&gt;&gt;</span>, <span class="ident">Json</span><span class="op">&lt;</span><span class="ident">Info</span><span class="op">&gt;</span>),
) <span class="op">-&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="ident">String</span><span class="op">&gt;</span> {
<span class="prelude-val">Ok</span>(<span class="macro">format</span><span class="macro">!</span>(<span class="string">&quot;Welcome {}!&quot;</span>, <span class="ident">info</span>.<span class="number">0</span>.<span class="ident">username</span>))
}
<span class="kw">fn</span> <span class="ident">main</span>() {
<span class="kw">let</span> <span class="ident">app</span> <span class="op">=</span> <span class="ident">App</span>::<span class="ident">new</span>().<span class="ident">resource</span>(
<span class="string">&quot;/{username}/index.html&quot;</span>, <span class="comment">// &lt;- define path parameters</span>
<span class="op">|</span><span class="ident">r</span><span class="op">|</span> <span class="ident">r</span>.<span class="ident">method</span>(<span class="ident">http</span>::<span class="ident">Method</span>::<span class="ident">GET</span>).<span class="ident">with</span>(<span class="ident">index</span>),
); <span class="comment">// &lt;- use `with` extractor</span>
}</pre>
</div><h4 id='method.with_config' class="method"><span id='with_config.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.with_config' class='fnname'>with_config</a>&lt;T, F, R, C&gt;(&amp;mut self, handler: F, cfg_f: C) <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(T) -&gt; R + 'static,<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../../actix_web/trait.Responder.html" title="trait actix_web::Responder">Responder</a> + 'static,<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../actix_web/trait.FromRequest.html" title="trait actix_web::FromRequest">FromRequest</a>&lt;S&gt; + 'static,<br>&nbsp;&nbsp;&nbsp;&nbsp;C: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(&amp;mut T::<a class="type" href="../../actix_web/trait.FromRequest.html#associatedtype.Config" title="type actix_web::FromRequest::Config">Config</a>),&nbsp;</span></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/actix_web/route.rs.html#200-210' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Set handler function. Same as <code>.with()</code> but it allows to configure
extractor.</p>
<pre class="rust rust-example-rendered">
<span class="attribute">#[<span class="ident">macro_use</span>]</span> <span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">serde_derive</span>;
<span class="kw">use</span> <span class="ident">actix_web</span>::{<span class="ident">http</span>, <span class="ident">App</span>, <span class="ident">Path</span>, <span class="prelude-ty">Result</span>};
<span class="doccomment">/// extract text data from request</span>
<span class="kw">fn</span> <span class="ident">index</span>(<span class="ident">body</span>: <span class="ident">String</span>) <span class="op">-&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="ident">String</span><span class="op">&gt;</span> {
<span class="prelude-val">Ok</span>(<span class="macro">format</span><span class="macro">!</span>(<span class="string">&quot;Body {}!&quot;</span>, <span class="ident">body</span>))
}
<span class="kw">fn</span> <span class="ident">main</span>() {
<span class="kw">let</span> <span class="ident">app</span> <span class="op">=</span> <span class="ident">App</span>::<span class="ident">new</span>().<span class="ident">resource</span>(<span class="string">&quot;/index.html&quot;</span>, <span class="op">|</span><span class="ident">r</span><span class="op">|</span> {
<span class="ident">r</span>.<span class="ident">method</span>(<span class="ident">http</span>::<span class="ident">Method</span>::<span class="ident">GET</span>)
.<span class="ident">with_config</span>(<span class="ident">index</span>, <span class="op">|</span><span class="ident">cfg</span><span class="op">|</span> { <span class="comment">// &lt;- register handler</span>
<span class="ident">cfg</span>.<span class="ident">limit</span>(<span class="number">4096</span>); <span class="comment">// &lt;- limit size of the payload</span>
})
});
}</pre>
</div><h4 id='method.with_async' class="method"><span id='with_async.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.with_async' class='fnname'>with_async</a>&lt;T, F, R, I, E&gt;(&amp;mut self, handler: F) <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(T) -&gt; R + 'static,<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="https://docs.rs/futures/0.1/futures/future/trait.Future.html" title="trait futures::future::Future">Future</a>&lt;Item = I, Error = E&gt; + 'static,<br>&nbsp;&nbsp;&nbsp;&nbsp;I: <a class="trait" href="../../actix_web/trait.Responder.html" title="trait actix_web::Responder">Responder</a> + 'static,<br>&nbsp;&nbsp;&nbsp;&nbsp;E: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;<a class="struct" href="../../actix_web/error/struct.Error.html" title="struct actix_web::error::Error">Error</a>&gt; + 'static,<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../actix_web/trait.FromRequest.html" title="trait actix_web::FromRequest">FromRequest</a>&lt;S&gt; + 'static,&nbsp;</span></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/actix_web/route.rs.html#241-250' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Set async handler function, use request extractor for parameters.
Also this method needs to be used if your handler function returns
<code>impl Future&lt;&gt;</code></p>
<pre class="rust rust-example-rendered">
<span class="attribute">#[<span class="ident">macro_use</span>]</span> <span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">serde_derive</span>;
<span class="kw">use</span> <span class="ident">actix_web</span>::{<span class="ident">http</span>, <span class="ident">App</span>, <span class="ident">Error</span>, <span class="ident">Path</span>};
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">Future</span>;
<span class="attribute">#[<span class="ident">derive</span>(<span class="ident">Deserialize</span>)]</span>
<span class="kw">struct</span> <span class="ident">Info</span> {
<span class="ident">username</span>: <span class="ident">String</span>,
}
<span class="doccomment">/// extract path info using serde</span>
<span class="kw">fn</span> <span class="ident">index</span>(<span class="ident">info</span>: <span class="ident">Path</span><span class="op">&lt;</span><span class="ident">Info</span><span class="op">&gt;</span>) <span class="op">-&gt;</span> <span class="ident">Box</span><span class="op">&lt;</span><span class="ident">Future</span><span class="op">&lt;</span><span class="ident">Item</span> <span class="op">=</span> <span class="kw-2">&amp;</span><span class="lifetime">&#39;static</span> <span class="ident">str</span>, <span class="ident">Error</span> <span class="op">=</span> <span class="ident">Error</span><span class="op">&gt;&gt;</span> {
<span class="macro">unimplemented</span><span class="macro">!</span>()
}
<span class="kw">fn</span> <span class="ident">main</span>() {
<span class="kw">let</span> <span class="ident">app</span> <span class="op">=</span> <span class="ident">App</span>::<span class="ident">new</span>().<span class="ident">resource</span>(
<span class="string">&quot;/{username}/index.html&quot;</span>, <span class="comment">// &lt;- define path parameters</span>
<span class="op">|</span><span class="ident">r</span><span class="op">|</span> <span class="ident">r</span>.<span class="ident">method</span>(<span class="ident">http</span>::<span class="ident">Method</span>::<span class="ident">GET</span>).<span class="ident">with_async</span>(<span class="ident">index</span>),
); <span class="comment">// &lt;- use `with` extractor</span>
}</pre>
</div><h4 id='method.with_async_config' class="method"><span id='with_async_config.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.with_async_config' class='fnname'>with_async_config</a>&lt;T, F, R, I, E, C&gt;(&amp;mut self, handler: F, cfg: C) <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(T) -&gt; R + 'static,<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="https://docs.rs/futures/0.1/futures/future/trait.Future.html" title="trait futures::future::Future">Future</a>&lt;Item = I, Error = E&gt; + 'static,<br>&nbsp;&nbsp;&nbsp;&nbsp;I: <a class="trait" href="../../actix_web/trait.Responder.html" title="trait actix_web::Responder">Responder</a> + 'static,<br>&nbsp;&nbsp;&nbsp;&nbsp;E: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;<a class="struct" href="../../actix_web/error/struct.Error.html" title="struct actix_web::error::Error">Error</a>&gt; + 'static,<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../actix_web/trait.FromRequest.html" title="trait actix_web::FromRequest">FromRequest</a>&lt;S&gt; + 'static,<br>&nbsp;&nbsp;&nbsp;&nbsp;C: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(&amp;mut T::<a class="type" href="../../actix_web/trait.FromRequest.html#associatedtype.Config" title="type actix_web::FromRequest::Config">Config</a>),&nbsp;</span></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/actix_web/route.rs.html#283-295' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Set async handler function, use request extractor for parameters.
This method allows to configure extractor.</p>
<pre class="rust rust-example-rendered">
<span class="attribute">#[<span class="ident">macro_use</span>]</span> <span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">serde_derive</span>;
<span class="kw">use</span> <span class="ident">actix_web</span>::{<span class="ident">http</span>, <span class="ident">App</span>, <span class="ident">Error</span>, <span class="ident">Form</span>};
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">Future</span>;
<span class="attribute">#[<span class="ident">derive</span>(<span class="ident">Deserialize</span>)]</span>
<span class="kw">struct</span> <span class="ident">Info</span> {
<span class="ident">username</span>: <span class="ident">String</span>,
}
<span class="doccomment">/// extract path info using serde</span>
<span class="kw">fn</span> <span class="ident">index</span>(<span class="ident">info</span>: <span class="ident">Form</span><span class="op">&lt;</span><span class="ident">Info</span><span class="op">&gt;</span>) <span class="op">-&gt;</span> <span class="ident">Box</span><span class="op">&lt;</span><span class="ident">Future</span><span class="op">&lt;</span><span class="ident">Item</span> <span class="op">=</span> <span class="kw-2">&amp;</span><span class="lifetime">&#39;static</span> <span class="ident">str</span>, <span class="ident">Error</span> <span class="op">=</span> <span class="ident">Error</span><span class="op">&gt;&gt;</span> {
<span class="macro">unimplemented</span><span class="macro">!</span>()
}
<span class="kw">fn</span> <span class="ident">main</span>() {
<span class="kw">let</span> <span class="ident">app</span> <span class="op">=</span> <span class="ident">App</span>::<span class="ident">new</span>().<span class="ident">resource</span>(
<span class="string">&quot;/{username}/index.html&quot;</span>, <span class="comment">// &lt;- define path parameters</span>
<span class="op">|</span><span class="ident">r</span><span class="op">|</span> <span class="ident">r</span>.<span class="ident">method</span>(<span class="ident">http</span>::<span class="ident">Method</span>::<span class="ident">GET</span>)
.<span class="ident">with_async_config</span>(<span class="ident">index</span>, <span class="op">|</span><span class="ident">cfg</span><span class="op">|</span> {
<span class="ident">cfg</span>.<span class="ident">limit</span>(<span class="number">4096</span>);
}),
); <span class="comment">// &lt;- use `with` extractor</span>
}</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-Default' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl&lt;S:&nbsp;'static&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a> for <a class="struct" href="../../actix_web/dev/struct.Route.html" title="struct actix_web::dev::Route">Route</a>&lt;S&gt;</code><a href='#impl-Default' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/actix_web/route.rs.html#30-37' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.default' class="method"><span id='default.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='https://doc.rust-lang.org/nightly/core/default/trait.Default.html#tymethod.default' class='fnname'>default</a>() -&gt; <a class="struct" href="../../actix_web/dev/struct.Route.html" title="struct actix_web::dev::Route">Route</a>&lt;S&gt;</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/actix_web/route.rs.html#31-36' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Returns the &quot;default value&quot; for a type. <a href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html#tymethod.default">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;S&gt; !<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="../../actix_web/dev/struct.Route.html" title="struct actix_web::dev::Route">Route</a>&lt;S&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;S&gt; !<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="../../actix_web/dev/struct.Route.html" title="struct actix_web::dev::Route">Route</a>&lt;S&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 = "actix_web";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>