1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-24 07:53:00 +01:00
actix-extras/actix_settings/index.html
2022-07-31 19:16:33 +00:00

70 lines
14 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="Easily manage Actix Webs settings from a TOML file and environment variables."><meta name="keywords" content="rust, rustlang, rust-lang, actix_settings"><title>actix_settings - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Semibold.ttf.woff2"><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="../ayu.css" disabled><link rel="stylesheet" type="text/css" href="../dark.css" disabled><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../storage.js"></script><script defer src="../crates.js"></script><script defer src="../main.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="icon" href="https://actix.rs/favicon.ico"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="sidebar-logo" href="../actix_settings/index.html"><div class="logo-container"><img src="https://actix.rs/img/logo.png" alt="logo"></div></a><h2 class="location"></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../actix_settings/index.html"><div class="logo-container">
<img src="https://actix.rs/img/logo.png" alt="logo"></div></a><h2 class="location"><a href="#">Crate actix_settings</a></h2><div class="sidebar-elems"><div class="block"><ul><li class="version">Version 0.6.0</li><li><a id="all-types" href="all.html">All Items</a></li></ul></div><section><div class="block"><ul><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li><li><a href="#traits">Traits</a></li><li><a href="#types">Type Definitions</a></li></ul></div></section></div></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../actix_settings/index.html">
<img src="https://actix.rs/img/logo.png" alt="logo"></a><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><button type="button">?</button></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../wheel.svg"></a></div></div></form></nav></div><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn"><span class="in-band">Crate <a class="mod" href="#">actix_settings</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span></h1><span class="out-of-band"><a class="srclink" href="../src/actix_settings/lib.rs.html#1-805">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Easily manage Actix Webs settings from a TOML file and environment variables.</p>
<p>To get started add a <a href="struct.BasicSettings.html#method.parse_toml"><code>Settings::parse_toml(&quot;./Server.toml&quot;)</code></a> call to the
top of your main function. This will create a template file with descriptions of all the
configurable settings. You can change or remove anything in that file and it will be picked up
the next time you run your application.</p>
<p>Overriding parts of the file can be done from values using <a href="struct.BasicSettings.html#method.override_field" title="Settings::override_field"><code>Settings::override_field</code></a> or from
the environment using <a href="struct.BasicSettings.html#method.override_field_with_env_var" title="Settings::override_field_with_env_var"><code>Settings::override_field_with_env_var</code></a>.</p>
<h2 id="examples"><a href="#examples">Examples</a></h2>
<p>See examples folder on GitHub for complete example.</p>
<div class='information'><div class='tooltip ignore'></div></div><div class="example-wrap"><pre class="rust rust-example-rendered ignore"><code><span class="kw">use</span> <span class="ident">actix_settings</span>::{<span class="ident">ApplySettings</span> <span class="kw">as</span> <span class="kw">_</span>, <span class="ident">Mode</span>, <span class="ident">Settings</span>};
<span class="attribute">#[<span class="ident">actix_web::main</span>]</span>
<span class="kw">async</span> <span class="kw">fn</span> <span class="ident">main</span>() -&gt; <span class="ident">std::io::Result</span><span class="op">&lt;</span>()<span class="op">&gt;</span> {
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">settings</span> <span class="op">=</span> <span class="ident">Settings::parse_toml</span>(<span class="string">&quot;./Server.toml&quot;</span>)
.<span class="ident">expect</span>(<span class="string">&quot;Failed to parse `Settings` from Server.toml&quot;</span>);
<span class="comment">// If the environment variable `$APPLICATION__HOSTS` is set,</span>
<span class="comment">// have its value override the `settings.actix.hosts` setting:</span>
<span class="ident">Settings::override_field_with_env_var</span>(<span class="kw-2">&amp;mut</span> <span class="ident">settings</span>.<span class="ident">actix</span>.<span class="ident">hosts</span>, <span class="string">&quot;APPLICATION__HOSTS&quot;</span>)<span class="question-mark">?</span>;
<span class="ident">init_logger</span>(<span class="kw-2">&amp;</span><span class="ident">settings</span>);
<span class="ident">HttpServer::new</span>({
<span class="comment">// clone settings into each worker thread</span>
<span class="kw">let</span> <span class="ident">settings</span> <span class="op">=</span> <span class="ident">settings</span>.<span class="ident">clone</span>();
<span class="kw">move</span> <span class="op">|</span><span class="op">|</span> {
<span class="ident">App::new</span>()
<span class="comment">// Include this `.wrap()` call for compression settings to take effect</span>
.<span class="ident">wrap</span>(<span class="ident">Condition::new</span>(
<span class="ident">settings</span>.<span class="ident">actix</span>.<span class="ident">enable_compression</span>,
<span class="ident">Compress::default</span>(),
))
<span class="comment">// add request logger</span>
.<span class="ident">wrap</span>(<span class="ident">Logger::default</span>())
<span class="comment">// make `Settings` available to handlers</span>
.<span class="ident">app_data</span>(<span class="ident">web::Data::new</span>(<span class="ident">settings</span>.<span class="ident">clone</span>()))
<span class="comment">// add request handlers as normal</span>
.<span class="ident">service</span>(<span class="ident">index</span>)
}
})
<span class="comment">// apply the `Settings` to Actix Web&#39;s `HttpServer`</span>
.<span class="ident">apply_settings</span>(<span class="kw-2">&amp;</span><span class="ident">settings</span>)
.<span class="ident">run</span>()
.<span class="kw">await</span>
}</code></pre></div>
</div></details><h2 id="structs" class="small-section-header"><a href="#structs">Structs</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.ActixSettings.html" title="actix_settings::ActixSettings struct">ActixSettings</a></div><div class="item-right docblock-short"><p>Settings types for Actix Web.</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Address.html" title="actix_settings::Address struct">Address</a></div><div class="item-right docblock-short"><p>A host/port pair for the server to bind to.</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.BasicSettings.html" title="actix_settings::BasicSettings struct">BasicSettings</a></div><div class="item-right docblock-short"><p>Wrapper for server and application-specific settings.</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.NoSettings.html" title="actix_settings::NoSettings struct">NoSettings</a></div><div class="item-right docblock-short"><p>Marker type representing no defined application-specific settings.</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Tls.html" title="actix_settings::Tls struct">Tls</a></div><div class="item-right docblock-short"><p>TLS (HTTPS) configuration.</p>
</div></div></div><h2 id="enums" class="small-section-header"><a href="#enums">Enums</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.AtError.html" title="actix_settings::AtError enum">AtError</a></div><div class="item-right docblock-short"><p>Errors that can be returned from methods in this crate.</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.Backlog.html" title="actix_settings::Backlog enum">Backlog</a></div><div class="item-right docblock-short"><p>The maximum number of pending connections.</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.KeepAlive.html" title="actix_settings::KeepAlive enum">KeepAlive</a></div><div class="item-right docblock-short"><p>The server keep-alive preference.</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.MaxConnectionRate.html" title="actix_settings::MaxConnectionRate enum">MaxConnectionRate</a></div><div class="item-right docblock-short"><p>The maximum per-worker concurrent TLS connection limit.</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.MaxConnections.html" title="actix_settings::MaxConnections enum">MaxConnections</a></div><div class="item-right docblock-short"><p>The maximum per-worker number of concurrent connections.</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.Mode.html" title="actix_settings::Mode enum">Mode</a></div><div class="item-right docblock-short"><p>Marker of intended deployment environment.</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.NumWorkers.html" title="actix_settings::NumWorkers enum">NumWorkers</a></div><div class="item-right docblock-short"><p>The number of workers that the server should start.</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.Timeout.html" title="actix_settings::Timeout enum">Timeout</a></div><div class="item-right docblock-short"><p>A timeout duration in milliseconds or seconds.</p>
</div></div></div><h2 id="traits" class="small-section-header"><a href="#traits">Traits</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.ApplySettings.html" title="actix_settings::ApplySettings trait">ApplySettings</a></div><div class="item-right docblock-short"><p>Extension trait for applying parsed settings to the server object.</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.Parse.html" title="actix_settings::Parse trait">Parse</a></div><div class="item-right docblock-short"><p>A specialized <code>FromStr</code> trait that returns <a href="enum.AtError.html" title="AtError"><code>AtError</code></a> errors</p>
</div></div></div><h2 id="types" class="small-section-header"><a href="#types">Type Definitions</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="type" href="type.AtResult.html" title="actix_settings::AtResult type">AtResult</a></div><div class="item-right docblock-short"><p>Convenience type alias for <code>Result&lt;T, AtError&gt;</code>.</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="type" href="type.Settings.html" title="actix_settings::Settings type">Settings</a></div><div class="item-right docblock-short"><p>Convenience type alias for <a href="struct.BasicSettings.html" title="BasicSettings"><code>BasicSettings</code></a> with no defined application-specific settings.</p>
</div></div></div></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="actix_settings" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.64.0-nightly (0f4bcadb4 2022-07-30)" ></div></body></html>