Skip to main content

AppEnvironment

Struct AppEnvironment 

Source
pub struct AppEnvironment {
Show 21 fields pub name: String, pub version_code: String, pub build_number: i32, pub log_sql: bool, pub server_count: usize, pub worker_count: usize, pub socket_count: usize, pub pg_url: String, pub redis_url: String, pub rabbitmq_url: String, pub rabbitmq_vhost: String, pub mongodb_url: String, pub es_url: String, pub es_api_key: String, pub server_port: u16, pub socket_port: u16, pub prefetch_count: usize, pub url: String, pub setup_mode: SetupMode, pub kind: EnvironmentKind, pub process_role: ProcessRole, /* private fields */
}
Expand description

Loaded service configuration. Obtain via AppEnvironment::get after provisioning.

Required keys are SERVICE_NAME, SERVICE_VERSION, BUILD_NUMBER, ENVIRONMENT_KIND, SERVER_PORT, SERVICE_URL, POSTGRESQL_URL, REDIS_URL, RABBITMQ_URL, and MONGODB_URL; loading fails with EnvError::MissingKeys when any are absent.

Fields§

§name: String

Service name from SERVICE_NAME.

§version_code: String

Service version from SERVICE_VERSION.

§build_number: i32

Build number from BUILD_NUMBER.

§log_sql: bool

Whether SQL statements are logged, from LOG_SQL (defaults to false).

§server_count: usize

Number of HTTP server instances, from SERVER_COUNT (defaults to 1).

§worker_count: usize

Number of worker instances, from WORKER_COUNT (defaults to 0).

§socket_count: usize

Number of socket server instances, from SOCKET_COUNT (defaults to 0).

§pg_url: String

Postgres connection URL from POSTGRESQL_URL.

§redis_url: String

Redis connection URL from REDIS_URL.

§rabbitmq_url: String

RabbitMQ connection URL from RABBITMQ_URL.

§rabbitmq_vhost: String

RabbitMQ virtual host from RABBITMQ_VHOST (defaults to "/").

§mongodb_url: String

MongoDB connection URL from MONGODB_URL.

§es_url: String

Elasticsearch URL from ELASTICSEARCH_URL (defaults to "<none>").

§es_api_key: String

Elasticsearch API key from ELASTICSEARCH_API_KEY (defaults to "<none>").

§server_port: u16

HTTP listen port from SERVER_PORT.

§socket_port: u16

Socket listen port from SOCKET_PORT (defaults to 8081).

§prefetch_count: usize

Queue prefetch count from PREFETCH_COUNT (defaults to 1).

§url: String

Public service URL from SERVICE_URL.

§setup_mode: SetupMode

Setup selector from SETUP_MODE (defaults to production).

§kind: EnvironmentKind

Deployment environment selector from ENVIRONMENT_KIND.

§process_role: ProcessRole

Process role from PROCESS_ROLE (defaults to worker).

Implementations§

Source§

impl AppEnvironment

Source

pub fn with_env_file(path: Option<&str>) -> Result<(), EnvError>

Provisions the singleton from the given dotenv file, or from .env plus the process environment when path is None. Idempotent: no-ops when already provisioned.

Returns EnvError::MissingKeys when a required key is absent, or EnvError::InvalidValue when a value fails to parse.

Source

pub fn get() -> &'static Self

Returns the provisioned environment.

Panics when AppEnvironment::with_env_file has not run yet.

Source

pub fn try_get() -> Option<&'static Self>

Returns the provisioned environment, or None when not yet provisioned.

Source

pub fn is_production(&self) -> bool

Reports whether the environment kind is production.

Source

pub fn should_log_sql(&self) -> bool

Reports whether SQL statement logging is enabled (LOG_SQL).

Source

pub fn get_value(&self, key: &str) -> Option<String>

Looks up key in the loaded map, falling back to the process environment. Returns None when absent in both.

Source

pub fn get_required(&self, key: &str) -> Result<String, EnvError>

Looks up key as in AppEnvironment::get_value. Returns EnvError::MissingKeys when absent in both.

Trait Implementations§

Source§

impl Clone for AppEnvironment

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 AppEnvironment

Source§

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

Formats the value using the given formatter. 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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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<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> CompatExt for T

Source§

fn compat(self) -> Compat<T>
where T: Sized,

Applies the Compat adapter by value. Read more
Source§

fn compat_ref(&self) -> Compat<&T>

Applies the Compat adapter by shared reference. Read more
Source§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the Compat adapter by mutable reference. Read more
Source§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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<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