Skip to main content

Config

Struct Config 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§name: String

The application’s name, from APP_NAME (Renox).

§env: Environment

The environment, from APP_ENV (local).

§debug: bool

Show error details and backtraces in responses. Never enable in production.

§url: String

The public base URL, from APP_URL (http://{host}:{port}).

§key: Option<String>

Secret used for signing and encryption. Required in production.

§host: IpAddr

The IP address to listen on, from APP_HOST (127.0.0.1).

§port: u16

The port to listen on, from APP_PORT (3000).

§views_path: PathBuf

Where templates live, from VIEWS_PATH.

§public_path: PathBuf

Files served as-is at the site root, from PUBLIC_PATH.

§session_lifetime: Duration

Inactivity before a session expires, from SESSION_LIFETIME in minutes (default 120).

§session_cookie: String

Name of the session cookie, from SESSION_COOKIE.

§session_driver: SessionDriver

Where 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: Duration

How long a “remember me” login lasts, from REMEMBER_LIFETIME in minutes (default 43200: 30 days).

§database_url: String

SQLite database, from DATABASE_URL, e.g. sqlite://storage/app.db.

§database_pool_size: u32

Maximum open connections, from DATABASE_POOL_SIZE.

§database_acquire_timeout: Duration

How 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: String

Default 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: String

Language used for keys missing in the request’s locale, from APP_FALLBACK_LOCALE.

§currency: String

The 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: PathBuf

Where translation files live, from LANG_PATH.

§mail: MailConfig

Mail settings, from MAIL_*.

§queue_workers: usize

Queue workers serve runs in-process, from QUEUE_WORKERS (0 turns them off).

§scheduler: bool

Whether serve runs scheduled tasks, from SCHEDULER.

§log_format: LogFormat

text (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: Zone

The 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: CacheStore

memory or database, from CACHE_STORE.

§storage_path: PathBuf

Where the app keeps runtime files (maintenance flag, uploads), from STORAGE_PATH.

§storage: StorageConfig

File storage, from STORAGE_DISK, S3_* and STORAGE_URL.

§upload_max_size: usize

Largest request body in bytes, from UPLOAD_MAX_SIZE in megabytes (default 10).

§csp: CspMode

The 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: AnalyticsConfig

Search engines and analytics; used only in production.

§trusted_proxies: TrustedProxies

Reverse 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

Source

pub fn load() -> Result<Self>

Loads .env (if present) and reads the configuration from the environment.

Source

pub fn from_env() -> Result<Self>

Reads the configuration from the environment only, without loading .env.

Source

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.

Source

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.

Source

pub fn addr(&self) -> SocketAddr

The address to listen on: host and port.

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Fake for T

Source§

fn fake<U>(&self) -> U
where Self: FakeBase<U>,

Source§

fn fake_with_rng<U, R>(&self, rng: &mut R) -> U
where R: RngExt + ?Sized, Self: FakeBase<U>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more