mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-23 23:51:06 +01:00
53 lines
11 KiB
HTML
53 lines
11 KiB
HTML
<!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 Web’s settings from a TOML file and environment variables."><title>actix_settings - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Regular-46f98efaafac5295.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/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-804b98a1284a310a.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="actix_settings" data-themes="" data-resource-suffix="" data-rustdoc-version="1.76.0-nightly (6a6287132 2023-12-17)" data-channel="nightly" data-search-js="search-2b6ce74ff89ae146.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../static.files/storage-f2adc0d6ca4d09fb.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-305769736d49e732.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-feafe1bb7466e4bd.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">☰</button><a class="logo-container" href="../actix_settings/index.html"><img src="https://actix.rs/img/logo.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../actix_settings/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../actix_settings/index.html">actix_settings</a><span class="version">0.7.1</span></h2></div><div class="sidebar-elems"><ul class="block">
|
||
<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 Aliases</a></li></ul></section></div></nav><div class="sidebar-resizer"></div>
|
||
<main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><div id="sidebar-button" tabindex="-1"><a href="../actix_settings/all.html" title="show sidebar"></a></div><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" tabindex="-1"><a href="../help.html" title="help">?</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-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Crate <a class="mod" href="#">actix_settings</a><button id="copy-path" 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="src" href="../src/actix_settings/lib.rs.html#1-820">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Easily manage Actix Web’s settings from a TOML file and environment variables.</p>
|
||
<p>To get started add a <a href="struct.BasicSettings.html#method.parse_toml" title="associated function actix_settings::BasicSettings::parse_toml"><code>Settings::parse_toml("./Server.toml")</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="associated function actix_settings::BasicSettings::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="associated function actix_settings::BasicSettings::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"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><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() -> std::io::Result<()> {
|
||
<span class="kw">let </span><span class="kw-2">mut </span>settings = Settings::parse_toml(<span class="string">"./Server.toml"</span>)
|
||
.expect(<span class="string">"Failed to parse `Settings` from Server.toml"</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">&mut </span>settings.actix.hosts, <span class="string">"APPLICATION__HOSTS"</span>)<span class="question-mark">?</span>;
|
||
|
||
init_logger(<span class="kw-2">&</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's `HttpServer`
|
||
</span>.apply_settings(<span class="kw-2">&</span>settings)
|
||
.run()
|
||
.<span class="kw">await
|
||
</span>}</code></pre></div>
|
||
</div></details><h2 id="structs" class="section-header"><a href="#structs">Structs</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.ActixSettings.html" title="struct actix_settings::ActixSettings">ActixSettings</a></div><div class="desc docblock-short">Settings types for Actix Web.</div></li><li><div class="item-name"><a class="struct" href="struct.Address.html" title="struct actix_settings::Address">Address</a></div><div class="desc docblock-short">A host/port pair for the server to bind to.</div></li><li><div class="item-name"><a class="struct" href="struct.BasicSettings.html" title="struct actix_settings::BasicSettings">BasicSettings</a></div><div class="desc docblock-short">Wrapper for server and application-specific settings.</div></li><li><div class="item-name"><a class="struct" href="struct.NoSettings.html" title="struct actix_settings::NoSettings">NoSettings</a></div><div class="desc docblock-short">Marker type representing no defined application-specific settings.</div></li><li><div class="item-name"><a class="struct" href="struct.Tls.html" title="struct actix_settings::Tls">Tls</a></div><div class="desc docblock-short">TLS (HTTPS) configuration.</div></li></ul><h2 id="enums" class="section-header"><a href="#enums">Enums</a></h2><ul class="item-table"><li><div class="item-name"><a class="enum" href="enum.Backlog.html" title="enum actix_settings::Backlog">Backlog</a></div><div class="desc docblock-short">The maximum number of pending connections.</div></li><li><div class="item-name"><a class="enum" href="enum.Error.html" title="enum actix_settings::Error">Error</a></div><div class="desc docblock-short">Errors that can be returned from methods in this crate.</div></li><li><div class="item-name"><a class="enum" href="enum.KeepAlive.html" title="enum actix_settings::KeepAlive">KeepAlive</a></div><div class="desc docblock-short">The server keep-alive preference.</div></li><li><div class="item-name"><a class="enum" href="enum.MaxConnectionRate.html" title="enum actix_settings::MaxConnectionRate">MaxConnectionRate</a></div><div class="desc docblock-short">The maximum per-worker concurrent TLS connection limit.</div></li><li><div class="item-name"><a class="enum" href="enum.MaxConnections.html" title="enum actix_settings::MaxConnections">MaxConnections</a></div><div class="desc docblock-short">The maximum per-worker number of concurrent connections.</div></li><li><div class="item-name"><a class="enum" href="enum.Mode.html" title="enum actix_settings::Mode">Mode</a></div><div class="desc docblock-short">Marker of intended deployment environment.</div></li><li><div class="item-name"><a class="enum" href="enum.NumWorkers.html" title="enum actix_settings::NumWorkers">NumWorkers</a></div><div class="desc docblock-short">The number of workers that the server should start.</div></li><li><div class="item-name"><a class="enum" href="enum.Timeout.html" title="enum actix_settings::Timeout">Timeout</a></div><div class="desc docblock-short">A timeout duration in milliseconds or seconds.</div></li></ul><h2 id="traits" class="section-header"><a href="#traits">Traits</a></h2><ul class="item-table"><li><div class="item-name"><a class="trait" href="trait.ApplySettings.html" title="trait actix_settings::ApplySettings">ApplySettings</a></div><div class="desc docblock-short">Extension trait for applying parsed settings to the server object.</div></li><li><div class="item-name"><a class="trait" href="trait.Parse.html" title="trait actix_settings::Parse">Parse</a></div><div class="desc docblock-short">A specialized <code>FromStr</code> trait that returns <a href="enum.Error.html" title="enum actix_settings::Error"><code>Error</code></a> errors</div></li></ul><h2 id="types" class="section-header"><a href="#types">Type Aliases</a></h2><ul class="item-table"><li><div class="item-name"><a class="type" href="type.Settings.html" title="type actix_settings::Settings">Settings</a></div><div class="desc docblock-short">Convenience type alias for <a href="struct.BasicSettings.html" title="struct actix_settings::BasicSettings"><code>BasicSettings</code></a> with no defined application-specific settings.</div></li></ul></section></div></main></body></html> |