pub struct BasicSettings<A> {
pub actix: ActixSettings,
pub application: A,
}Expand description
Wrapper for server and application-specific settings.
Fields§
§actix: ActixSettingsActix Web server settings.
application: AApplication-specific settings.
Implementations§
Source§impl<A> BasicSettings<A>where
A: DeserializeOwned,
impl<A> BasicSettings<A>where
A: DeserializeOwned,
Sourcepub fn parse_toml<P>(filepath: P) -> Result<Self, Error>
pub fn parse_toml<P>(filepath: P) -> Result<Self, Error>
Parse an instance of Self from a TOML file located at filepath.
If the file doesn’t exist, it is generated from the default TOML template, after which the newly generated file is read in and parsed.
Sourcepub fn from_default_template() -> Self
pub fn from_default_template() -> Self
Parse an instance of Self straight from the default TOML template.
Sourcepub fn from_template(template: &str) -> Result<Self, Error>
pub fn from_template(template: &str) -> Result<Self, Error>
Parse an instance of Self straight from the default TOML template.
Sourcepub fn write_toml_file<P>(filepath: P) -> Result<(), Error>
pub fn write_toml_file<P>(filepath: P) -> Result<(), Error>
Writes the default TOML template to a new file, located at filepath.
§Errors
Returns a FileExists error if a file already exists at that
location.
Sourcepub fn override_field<F, V>(field: &mut F, value: V) -> Result<(), Error>
pub fn override_field<F, V>(field: &mut F, value: V) -> Result<(), Error>
Attempts to parse value and override the referenced field.
§Examples
use actix_settings::{Settings, Mode};
let mut settings = Settings::from_default_template();
assert_eq!(settings.actix.mode, Mode::Development);
Settings::override_field(&mut settings.actix.mode, "production")?;
assert_eq!(settings.actix.mode, Mode::Production);Sourcepub fn override_field_with_env_var<F, N>(
field: &mut F,
var_name: N,
) -> Result<(), Error>
pub fn override_field_with_env_var<F, N>( field: &mut F, var_name: N, ) -> Result<(), Error>
Attempts to read an environment variable, parse it, and override the referenced field.
§Examples
use actix_settings::{Settings, Mode};
std::env::set_var("OVERRIDE__MODE", "production");
let mut settings = Settings::from_default_template();
assert_eq!(settings.actix.mode, Mode::Development);
Settings::override_field_with_env_var(&mut settings.actix.mode, "OVERRIDE__MODE")?;
assert_eq!(settings.actix.mode, Mode::Production);Trait Implementations§
Source§impl<F, I, S, B, A> ApplySettings<BasicSettings<A>> for HttpServer<F, I, S, B>where
F: Fn() -> I + Send + Clone + 'static,
I: IntoServiceFactory<S, Request>,
S: ServiceFactory<Request, Config = AppConfig> + 'static,
S::Error: Into<Error> + 'static,
S::InitError: Debug,
S::Response: Into<Response<B>> + 'static,
S::Future: 'static,
B: MessageBody + 'static,
A: DeserializeOwned,
impl<F, I, S, B, A> ApplySettings<BasicSettings<A>> for HttpServer<F, I, S, B>where
F: Fn() -> I + Send + Clone + 'static,
I: IntoServiceFactory<S, Request>,
S: ServiceFactory<Request, Config = AppConfig> + 'static,
S::Error: Into<Error> + 'static,
S::InitError: Debug,
S::Response: Into<Response<B>> + 'static,
S::Future: 'static,
B: MessageBody + 'static,
A: DeserializeOwned,
Source§fn apply_settings(self, settings: &BasicSettings<A>) -> Self
fn apply_settings(self, settings: &BasicSettings<A>) -> Self
👎Deprecated: Prefer
try_apply_settings().Applies some settings object value to
self. Read moreSource§fn try_apply_settings(self, settings: &BasicSettings<A>) -> Result<Self, Error>
fn try_apply_settings(self, settings: &BasicSettings<A>) -> Result<Self, Error>
Applies some settings object value to
self. Read moreSource§impl<A: Clone> Clone for BasicSettings<A>
impl<A: Clone> Clone for BasicSettings<A>
Source§fn clone(&self) -> BasicSettings<A>
fn clone(&self) -> BasicSettings<A>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<A: Debug> Debug for BasicSettings<A>
impl<A: Debug> Debug for BasicSettings<A>
Source§impl<'de, A> Deserialize<'de> for BasicSettings<A>where
A: Deserialize<'de>,
impl<'de, A> Deserialize<'de> for BasicSettings<A>where
A: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<A: Hash> Hash for BasicSettings<A>
impl<A: Hash> Hash for BasicSettings<A>
Source§impl<A: PartialEq> PartialEq for BasicSettings<A>
impl<A: PartialEq> PartialEq for BasicSettings<A>
impl<A: Eq> Eq for BasicSettings<A>
impl<A> StructuralPartialEq for BasicSettings<A>
Auto Trait Implementations§
impl<A> Freeze for BasicSettings<A>where
A: Freeze,
impl<A> RefUnwindSafe for BasicSettings<A>where
A: RefUnwindSafe,
impl<A> Send for BasicSettings<A>where
A: Send,
impl<A> Sync for BasicSettings<A>where
A: Sync,
impl<A> Unpin for BasicSettings<A>where
A: Unpin,
impl<A> UnwindSafe for BasicSettings<A>where
A: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more