Crate actix_settings
source · [−]Expand description
Easily manage Actix Web’s settings from a TOML file and environment variables.
To get started add a Settings::parse_toml("./Server.toml")
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.
Overriding parts of the file can be done from values using Settings::override_field
or from
the environment using Settings::override_field_with_env_var
.
Examples
See examples folder on GitHub for complete example.
use actix_settings::{ApplySettings as _, Mode, Settings};
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let mut settings = Settings::parse_toml("./Server.toml")
.expect("Failed to parse `Settings` from Server.toml");
// If the environment variable `$APPLICATION__HOSTS` is set,
// have its value override the `settings.actix.hosts` setting:
Settings::override_field_with_env_var(&mut settings.actix.hosts, "APPLICATION__HOSTS")?;
init_logger(&settings);
HttpServer::new({
// clone settings into each worker thread
let settings = settings.clone();
move || {
App::new()
// Include this `.wrap()` call for compression settings to take effect
.wrap(Condition::new(
settings.actix.enable_compression,
Compress::default(),
))
// add request logger
.wrap(Logger::default())
// make `Settings` available to handlers
.app_data(web::Data::new(settings.clone()))
// add request handlers as normal
.service(index)
}
})
// apply the `Settings` to Actix Web's `HttpServer`
.apply_settings(&settings)
.run()
.await
}
Structs
Settings types for Actix Web.
A host/port pair for the server to bind to.
Wrapper for server and application-specific settings.
Marker type representing no defined application-specific settings.
TLS (HTTPS) configuration.
Enums
The maximum number of pending connections.
Errors that can be returned from methods in this crate.
The server keep-alive preference.
The maximum per-worker concurrent TLS connection limit.
The maximum per-worker number of concurrent connections.
Marker of intended deployment environment.
The number of workers that the server should start.
A timeout duration in milliseconds or seconds.
Traits
Extension trait for applying parsed settings to the server object.
A specialized FromStr
trait that returns [AtError
] errors
Type Definitions
Convenience type alias for BasicSettings
with no defined application-specific settings.