Skip to main content

Environments

Struct Environments 

Source
pub struct Environments { /* private fields */ }
Expand description

Engine-owned environment system: definitions + resolution + active-env state.

Implementations§

Source§

impl Environments

Source

pub fn new(default_env: impl Into<String>) -> Self

Creates an environment system with the given default environment name.

Source

pub fn with_environment( self, name: impl Into<String>, def: EnvironmentDef, ) -> Self

Registers (or replaces) a compiled-in environment definition.

Source

pub fn with_config_file(self, enabled: bool) -> Self

Enables loading <config-dir>/<app_id>/environments.toml during resolution.

Source

pub fn with_app_id(self, app_id: impl Into<String>) -> Self

Sets the application id used to locate the config file.

The consumer must set this to the same app_id passed to CliConfig::new before sharing the Environments with both CliConfig::with_environments and PkceAuthProvider::with_environments (with the pkce-auth feature), or config_file_path returns None and the environments.toml file layer silently resolves empty.

Source

pub fn with_config_file_path_override(self, path: PathBuf) -> Self

Test/advanced seam: force the environments file path.

Source

pub fn default_env(&self) -> &str

The default environment name.

Source

pub fn list(&self) -> Vec<String>

Enumerable environment names (compiled-in + file-defined), sorted.

Any error from reading or parsing the environments file (missing file, permission/read error, or malformed TOML) is silently swallowed and only the compiled-in names are returned. Use resolve when you need those errors surfaced; a fallible listing variant can be added later if needed.

§Blocking

When the config-file layer is enabled, this performs synchronous filesystem I/O to read and parse environments.toml (like resolve). Avoid calling it repeatedly on a latency-sensitive async path.

Source

pub fn resolve(&self, name: &str) -> Result<Environment>

Resolves name by merging compiled defaults, the config file, and <ENV>_* env-var overrides (later wins) into an Environment.

When only client_id was set on the matching layer(s), the returned Environment’s oauth.auth_url / oauth.token_url will be empty strings. Consumers should treat empty endpoint strings as “fall back to the provider’s default base endpoints”.

§Blocking

When the config-file layer is enabled (via with_config_file), this performs synchronous filesystem I/O to read and parse environments.toml. Resolve the environment once at startup (or off the latency-sensitive path) rather than calling it per request inside an async handler.

§Errors

Returns an error when name is not known to any layer or when the environments file exists but cannot be read or parsed.

Source

pub fn config_file_path(&self) -> Option<PathBuf>

Path to environments.toml next to the engine config file, or None when the file layer is disabled or the config dir cannot be determined.

Source

pub fn active_from_config(config: &ConfigFile) -> Option<String>

Reads the persisted active environment from a loaded config file.

Source

pub fn effective_active( &self, flag: Option<&str>, config: &ConfigFile, ) -> String

Resolves the active environment name with precedence: explicit --env override > persisted active > configured default.

Source

pub fn persist_active(&self, name: &str) -> Result<()>

Persists name as the active environment (loads, sets, saves a fresh config file for app_id). Validates that name resolves first.

§Errors

Returns an error when name does not resolve to a known environment, or when the config file cannot be written.

Trait Implementations§

Source§

impl Clone for Environments

Source§

fn clone(&self) -> Environments

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 Environments

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

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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