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

52 lines
12 KiB
HTML
Raw Normal View History

<!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="../static.files/SourceSerif4-Regular-1f7d512b176f0f72.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Bold-124a1ca42af929b6.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-9e69e4c014d22d53.css" id="mainThemeStyle"><link rel="stylesheet" id="themeStyle" href="../static.files/light-4743e13df3dfe8c4.css"><link rel="stylesheet" disabled href="../static.files/dark-0e1b889528bd466b.css"><link rel="stylesheet" disabled href="../static.files/ayu-65289d5d067c7c66.css"><script id="default-settings" ></script><script src="../static.files/storage-d43fa987303ecbbb.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-4a084badb5778746.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-13285aec31fa243e.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></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"><ul class="block"><li class="version">Version 0.6.0</li><li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><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></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../static.files/wheel-5ec35bf9ca753509.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Crate <a class="mod" href="#">actix_settings</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../static.files/clipboard-7571035ce49a181d.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../src/actix_settings/lib.rs.html#1-811">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>&#x2212;</span>]</button></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="example-wrap ignore"><div class='tooltip'></div><pre class="rust rust-example-rendered"><code><span class="kw">use </span>actix_settings::{ApplySettings <span class="kw">as _</span>, Mode, Settings};
<span class="attr">#[actix_web::main]
</span><span class="kw">async fn </span>main() -&gt; std::io::Result&lt;()&gt; {
<span class="kw">let </span><span class="kw-2">mut </span>settings = Settings::parse_toml(<span class="string">&quot;./Server.toml&quot;</span>)
.expect(<span class="string">&quot;Failed to parse `Settings` from Server.toml&quot;</span>);
<span class="comment">// If the environment variable `$APPLICATION__HOSTS` is set,
// have its value override the `settings.actix.hosts` setting:
</span>Settings::override_field_with_env_var(<span class="kw-2">&amp;mut </span>settings.actix.hosts, <span class="string">&quot;APPLICATION__HOSTS&quot;</span>)<span class="question-mark">?</span>;
init_logger(<span class="kw-2">&amp;</span>settings);
HttpServer::new({
<span class="comment">// clone settings into each worker thread
</span><span class="kw">let </span>settings = settings.clone();
<span class="kw">move </span>|| {
App::new()
<span class="comment">// Include this `.wrap()` call for compression settings to take effect
</span>.wrap(Condition::new(
settings.actix.enable_compression,
Compress::default(),
))
<span class="comment">// add request logger
</span>.wrap(Logger::default())
<span class="comment">// make `Settings` available to handlers
</span>.app_data(web::Data::new(settings.clone()))
<span class="comment">// add request handlers as normal
</span>.service(index)
}
})
<span class="comment">// apply the `Settings` to Actix Web&#39;s `HttpServer`
</span>.apply_settings(<span class="kw-2">&amp;</span>settings)
.run()
.<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">Settings types for Actix Web.</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">A host/port pair for the server to bind to.</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">Wrapper for server and application-specific settings.</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">Marker type representing no defined application-specific settings.</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">TLS (HTTPS) configuration.</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.Backlog.html" title="actix_settings::Backlog enum">Backlog</a></div><div class="item-right docblock-short">The maximum number of pending connections.</div></div><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.Error.html" title="actix_settings::Error enum">Error</a></div><div class="item-right docblock-short">Errors that can be returned from methods in this crate.</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">The server keep-alive preference.</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">The maximum per-worker concurrent TLS connection limit.</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">The maximum per-worker number of concurrent connections.</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">Marker of intended deployment environment.</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">The number of workers that the server should start.</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">A timeout duration in milliseconds or seconds.</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">Extension trait for applying parsed settings to the server object.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.Parse.html" title="actix_settings::