1
0
mirror of https://github.com/actix/actix-website synced 2024-11-24 16:52:59 +01:00
actix-website/static/api/actix-web/0.7.0/actix_web/fs/struct.StaticFiles.html

46 lines
20 KiB
HTML
Raw Normal View History

2018-07-21 13:09:47 +02:00
<!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 `StaticFiles` struct in crate `actix_web`."><meta name="keywords" content="rust, rustlang, rust-lang, StaticFiles"><title>actix_web::fs::StaticFiles - 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 StaticFiles</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#methods">Methods</a><div class="sidebar-links"><a href="#method.new">new</a><a href="#method.with_pool">with_pool</a><a href="#method.with_config">with_config</a><a href="#method.with_config_pool">with_config_pool</a><a href="#method.show_files_listing">show_files_listing</a><a href="#method.files_listing_renderer">files_listing_renderer</a><a href="#method.index_file">index_file</a><a href="#method.default_handler">default_handler</a></div><a class="sidebar-title" href="#implementations">Trait Implementations</a><div class="sidebar-links"><a href="#impl-Handler%3CS%3E">Handler&lt;S&gt;</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'>fs</a></p><script>window.sidebarCurrent = {name: 'StaticFiles', 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'>fs</a>::<wbr><a class="struct" href=''>StaticFiles</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/fs.rs.html#640-650' title='goto source code'>[src]</a></span></h1><div class="docblock type-decl"><pre class='rust struct'>pub struct StaticFiles&lt;S, C&nbsp;=&nbsp;<a class="struct" href="../../actix_web/fs/struct.DefaultConfig.html" title="struct actix_web::fs::DefaultConfig">DefaultConfig</a>&gt; { /* fields omitted */ }</pre></div><div class='docblock'><p>Static files handling</p>
<p><code>StaticFile</code> handler must be registered with <code>App::handler()</code> method,
because <code>StaticFile</code> handler requires access sub-path information.</p>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">actix_web</span>::{<span class="ident">fs</span>, <span class="ident">App</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">handler</span>(<span class="string">&quot;/static&quot;</span>, <span class="ident">fs</span>::<span class="ident">StaticFiles</span>::<span class="ident">new</span>(<span class="string">&quot;.&quot;</span>).<span class="ident">unwrap</span>())
.<span class="ident">finish</span>();
}</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;S:&nbsp;'static&gt; <a class="struct" href="../../actix_web/fs/struct.StaticFiles.html" title="struct actix_web::fs::StaticFiles">StaticFiles</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/fs.rs.html#652-669' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.new' class="method"><span id='new.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.new' class='fnname'>new</a>&lt;T:&nbsp;<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="https://doc.rust-lang.org/nightly/std/path/struct.PathBuf.html" title="struct std::path::PathBuf">PathBuf</a>&gt;&gt;(dir: T) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../../actix_web/fs/struct.StaticFiles.html" title="struct actix_web::fs::StaticFiles">StaticFiles</a>&lt;S&gt;, <a class="struct" href="../../actix_web/error/struct.Error.html" title="struct actix_web::error::Error">Error</a>&gt;</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/actix_web/fs.rs.html#658-660' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Create new <code>StaticFiles</code> instance for specified base directory.</p>
<p><code>StaticFile</code> uses <code>CpuPool</code> for blocking filesystem operations.
By default pool with 20 threads is used.
Pool size can be changed by setting ACTIX_CPU_POOL environment variable.</p>
</div><h4 id='method.with_pool' class="method"><span id='with_pool.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.with_pool' class='fnname'>with_pool</a>&lt;T:&nbsp;<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="https://doc.rust-lang.org/nightly/std/path/struct.PathBuf.html" title="struct std::path::PathBuf">PathBuf</a>&gt;&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;dir: T, <br>&nbsp;&nbsp;&nbsp;&nbsp;pool: CpuPool<br>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../../actix_web/fs/struct.StaticFiles.html" title="struct actix_web::fs::StaticFiles">StaticFiles</a>&lt;S&gt;, <a class="struct" href="../../actix_web/error/struct.Error.html" title="struct actix_web::error::Error">Error</a>&gt;</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/actix_web/fs.rs.html#664-668' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Create new <code>StaticFiles</code> instance for specified base directory and
<code>CpuPool</code>.</p>
</div></div><h3 id='impl-1' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl&lt;S:&nbsp;'static, C:&nbsp;<a class="trait" href="../../actix_web/fs/trait.StaticFileConfig.html" title="trait actix_web::fs::StaticFileConfig">StaticFileConfig</a>&gt; <a class="struct" href="../../actix_web/fs/struct.StaticFiles.html" title="struct actix_web::fs::StaticFiles">StaticFiles</a>&lt;S, C&gt;</code><a href='#impl-1' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/actix_web/fs.rs.html#671-778' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><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:&nbsp;<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="https://doc.rust-lang.org/nightly/std/path/struct.PathBuf.html" title="struct std::path::PathBuf">PathBuf</a>&gt;&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;dir: T, <br>&nbsp;&nbsp;&nbsp;&nbsp;config: C<br>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../../actix_web/fs/struct.StaticFiles.html" title="struct actix_web::fs::StaticFiles">StaticFiles</a>&lt;S, C&gt;, <a class="struct" href="../../actix_web/error/struct.Error.html" title="struct actix_web::error::Error">Error</a>&gt;</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/actix_web/fs.rs.html#675-680' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Create new <code>StaticFiles</code> instance for specified base directory.</p>
<p>Identical with <code>new</code> but allows to specify configiration to use.</p>
</div><h4 id='method.with_config_pool' class="method"><span id='with_config_pool.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.with_config_pool' class='fnname'>with_config_pool</a>&lt;T:&nbsp;<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="https://doc.rust-lang.org/nightly/std/path/struct.PathBuf.html" title="struct std::path::PathBuf">PathBuf</a>&gt;&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;dir: T, <br>&nbsp;&nbsp;&nbsp;&nbsp;pool: CpuPool, <br>&nbsp;&nbsp;&nbsp;&nbsp;_: C<br>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../../actix_web/fs/struct.StaticFiles.html" title="struct actix_web::fs::StaticFiles">StaticFiles</a>&lt;S, C&gt;, <a class="struct" href="../../actix_web/error/struct.Error.html" title="struct actix_web::error::Error">Error</a>&gt;</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/actix_web/fs.rs.html#684-706' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Create new <code>StaticFiles</code> instance for specified base directory with config and
<code>CpuPool</code>.</p>
</div><h4 id='method.show_files_listing' class="method"><span id='show_files_listing.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.show_files_listing' class='fnname'>show_files_listing</a>(self) -&gt; Self</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/actix_web/fs.rs.html#711-714' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Show files listing for directories.</p>
<p>By default show files listing is disabled.</p>
</div><h4 id='method.files_listing_renderer' class="method"><span id='files_listing_renderer.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.files_listing_renderer' class='fnname'>files_listing_renderer</a>&lt;F&gt;(self, f: F) -&gt; Self <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;'r <a class="struct" href="../../actix_web/fs/struct.Directory.html" title="struct actix_web::fs::Directory">Directory</a>, &amp;'s <a class="struct" href="../../actix_web/struct.HttpRequest.html" title="struct actix_web::HttpRequest">HttpRequest</a>&lt;S&gt;) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../../actix_web/struct.HttpResponse.html" title="struct actix_web::HttpResponse">HttpResponse</a>, <a class="struct" href="https://doc.rust-lang.org/nightly/std/io/error/struct.Error.html" title="struct std::io::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/fs.rs.html#717-725' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Set custom directory renderer</p>
</div><h4 id='method.index_file' class="method"><span id='index_file.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.index_file' class='fnname'>index_file</a>&lt;T:&nbsp;<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="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;&gt;(self, index: T) -&gt; <a class="struct" href="../../actix_web/fs/struct.StaticFiles.html" title="struct actix_web::fs::StaticFiles">StaticFiles</a>&lt;S, C&gt;</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/actix_web/fs.rs.html#731-734' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Set index file</p>
<p>Redirects to specific index file for directory &quot;/&quot; instead of
showing files listing.</p>
</div><h4 id='method.default_handler' class="method"><span id='default_handler.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.default_handler' class='fnname'>default_handler</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;(self, handler: H) -&gt; <a class="struct" href="../../actix_web/fs/struct.StaticFiles.html" title="struct actix_web::fs::StaticFiles">StaticFiles</a>&lt;S, C&gt;</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/actix_web/fs.rs.html#737-740' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Sets default handler which is used when no matched file could be found.</p>
</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-Handler%3CS%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl&lt;S:&nbsp;'static, C:&nbsp;'static + <a class="trait" href="../../actix_web/fs/trait.StaticFileConfig.html" title="trait actix_web::fs::StaticFileConfig">StaticFileConfig</a>&gt; <a class="trait" href="../../actix_web/dev/trait.Handler.html" title="trait actix_web::dev::Handler">Handler</a>&lt;S&gt; for <a class="struct" href="../../actix_web/fs/struct.StaticFiles.html" title="struct actix_web::fs::StaticFiles">StaticFiles</a>&lt;S, C&gt;</code><a href='#impl-Handler%3CS%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/actix_web/fs.rs.html#780-789' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='associatedtype.Result' class="type"><span id='Result.t' class='invisible'><code>type <a href='../../actix_web/dev/trait.Handler.html#associatedtype.Result' class="type">Result</a> = <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../../actix_web/dev/struct.AsyncResult.html" title="struct actix_web::dev::AsyncResult">AsyncResult</a>&lt;<a class="struct" href="../../actix_web/struct.HttpResponse.html" title="struct actix_web::HttpResponse">HttpResponse</a>&gt;, <a class="struct" href="../../actix_web/error/struct.Error.html" title="struct actix_web::error::Error">Error</a>&gt;</code></span></h4>
<div class='docblock'><p>The type of value that handler will return.</p>
</div><h4 id='method.handle' class="method"><span id='handle.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='../../actix_web/dev/trait.Handler.html#tymethod.handle' class='fnname'>handle</a>(&amp;self, req: &amp;<a class="struct" href="../../actix_web/struct.HttpRequest.html" title="struct actix_web::HttpRequest">HttpRequest</a>&lt;S&gt;) -&gt; Self::<a class="type" href="../../actix_web/dev/trait.Handler.html#associatedtype.Result" title="type actix_web::dev::Handler::Result">Result</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/actix_web/fs.rs.html#783-788' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Handle request</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, C&nbsp;=&nbsp;<a class="struct" href="../../actix_web/fs/struct.DefaultConfig.html" title="struct actix_web::fs::DefaultConfig">DefaultConfig</a>&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/fs/struct.StaticFiles.html" title="struct actix_web::fs::StaticFiles">StaticFiles</a>&lt;S, C&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, C&nbsp;=&nbsp;<a class="struct" href="../../actix_web/fs/struct.DefaultConfig.html" title="struct actix_web::fs::DefaultConfig">DefaultConfig</a>&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/fs/struct.StaticFiles.html" title="struct actix_web::fs::StaticFiles">StaticFiles</a>&lt;S, C&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>