#[non_exhaustive]pub struct Config {Show 37 fields
pub name: String,
pub env: Environment,
pub debug: bool,
pub url: String,
pub key: Option<String>,
pub host: IpAddr,
pub port: u16,
pub views_path: PathBuf,
pub public_path: PathBuf,
pub session_lifetime: Duration,
pub session_cookie: String,
pub session_driver: SessionDriver,
pub remember_lifetime: Duration,
pub database_url: String,
pub database_pool_size: u32,
pub database_acquire_timeout: Duration,
pub database_statement_timeout: Option<Duration>,
pub request_timeout: Option<Duration>,
pub locale: String,
pub fallback_locale: String,
pub currency: String,
pub lang_path: PathBuf,
pub mail: MailConfig,
pub queue_workers: usize,
pub scheduler: bool,
pub log_format: LogFormat,
pub log_file: Option<PathBuf>,
pub timezone: Zone,
pub cache_store: CacheStore,
pub storage_path: PathBuf,
pub storage: StorageConfig,
pub upload_max_size: usize,
pub csp: CspMode,
pub vars: HashMap<String, String>,
pub analytics: AnalyticsConfig,
pub trusted_proxies: TrustedProxies,
pub trusted_hosts: Vec<String>,
}Expand description
Application configuration, read from the process environment and .env.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.name: StringThe application’s name, from APP_NAME (Renox).
env: EnvironmentThe environment, from APP_ENV (local).
debug: boolShow error details and backtraces in responses. Never enable in production.
url: StringThe public base URL, from APP_URL (http://{host}:{port}).
key: Option<String>Secret used for signing and encryption. Required in production.
host: IpAddrThe IP address to listen on, from APP_HOST (127.0.0.1).
port: u16The port to listen on, from APP_PORT (3000).
views_path: PathBufWhere templates live, from VIEWS_PATH.
public_path: PathBufFiles served as-is at the site root, from PUBLIC_PATH.
session_lifetime: DurationInactivity before a session expires, from SESSION_LIFETIME in
minutes (default 120).
Name of the session cookie, from SESSION_COOKIE.
session_driver: SessionDriverWhere sessions live, from SESSION_DRIVER: cookie (default: the
whole session in an encrypted cookie) or database (the cookie holds
an id; the sessions table holds the rest).
remember_lifetime: DurationHow long a “remember me” login lasts, from REMEMBER_LIFETIME in
minutes (default 43200: 30 days).
database_url: StringSQLite database, from DATABASE_URL, e.g. sqlite://storage/app.db.
database_pool_size: u32Maximum open connections, from DATABASE_POOL_SIZE.
database_acquire_timeout: DurationHow long a query waits for a free connection before failing, from
DATABASE_ACQUIRE_TIMEOUT in seconds (default 5).
database_statement_timeout: Option<Duration>Longest a PostgreSQL statement may run, from DATABASE_STATEMENT_TIMEOUT
in seconds (default 30; 0 for none).
request_timeout: Option<Duration>Longest a request may take to answer, from REQUEST_TIMEOUT in
seconds (default 60; 0 for none). Streaming a response isn’t counted.
locale: StringDefault language of the app, from APP_LOCALE. Renox’s own texts are
English; other locales need a lang file (resources/lang/es.json).
fallback_locale: StringLanguage used for keys missing in the request’s locale, from APP_FALLBACK_LOCALE.
currency: StringThe currency of the money template filter, an ISO 4217 code, from
APP_CURRENCY (default USD): USD shows $75.00, EUR
€75.00, IDR Rp 75,000, with the page’s separators.
lang_path: PathBufWhere translation files live, from LANG_PATH.
mail: MailConfigMail settings, from MAIL_*.
queue_workers: usizeQueue workers serve runs in-process, from QUEUE_WORKERS (0 turns them off).
scheduler: boolWhether serve runs scheduled tasks, from SCHEDULER.
log_format: LogFormattext (default) or json (one object per line), from LOG_FORMAT.
log_file: Option<PathBuf>Where logs go instead of stdout, from LOG_FILE (appended to).
timezone: ZoneThe zone of scheduled times and the date filter, from
APP_TIMEZONE: an IANA name (Asia/Jakarta), an offset (+07:00) or
UTC. See crate::timezone::Zone.
cache_store: CacheStorememory or database, from CACHE_STORE.
storage_path: PathBufWhere the app keeps runtime files (maintenance flag, uploads), from STORAGE_PATH.
storage: StorageConfigFile storage, from STORAGE_DISK, S3_* and STORAGE_URL.
upload_max_size: usizeLargest request body in bytes, from UPLOAD_MAX_SIZE in megabytes (default 10).
csp: CspModeThe Content-Security-Policy, from CSP (relaxed, strict or off).
vars: HashMap<String, String>Values var() returns before looking at the environment, e.g. a
webhook secret set in a test with TestApp::with_config.
analytics: AnalyticsConfigSearch engines and analytics; used only in production.
trusted_proxies: TrustedProxiesReverse proxies whose X-Forwarded-For is believed, from TRUSTED_PROXIES.
trusted_hosts: Vec<String>Host names the app answers, from TRUSTED_HOSTS (comma-separated;
*.example.com for subdomains). Empty: any host. When set, APP_URL’s
host is allowed too, and other hosts get a 400.
Implementations§
Source§impl Config
impl Config
Sourcepub fn load() -> Result<Self>
pub fn load() -> Result<Self>
Loads .env (if present) and reads the configuration from the environment.
Sourcepub fn from_env() -> Result<Self>
pub fn from_env() -> Result<Self>
Reads the configuration from the environment only, without loading .env.
Sourcepub fn from_vars(get: impl Fn(&str) -> Option<String>) -> Result<Self>
pub fn from_vars(get: impl Fn(&str) -> Option<String>) -> Result<Self>
Reads the configuration from get (a variable’s value by name), e.g.
a map in a test: Config::from_vars(|name| vars.get(name).cloned()).
A value that doesn’t fit is an error naming its variable.
Sourcepub fn var(&self, name: &str) -> Option<String>
pub fn var(&self, name: &str) -> Option<String>
Any other setting, e.g. an API key: config.vars, else the
environment (which includes .env). Empty values count as missing.
Sourcepub fn addr(&self) -> SocketAddr
pub fn addr(&self) -> SocketAddr
The address to listen on: host and port.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnsafeUnpin for Config
impl UnwindSafe for Config
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more