pub struct Config { /* private fields */ }Expand description
Immutable runtime configuration, built once at startup.
Cloned per request by the gate middleware (from_fn_with_state
requires the state to be Clone), which is why fields are cheap to
copy/clone (Hash is Copy, String is Clone).
Implementations§
Source§impl Config
impl Config
Sourcepub fn from_env() -> Result<Self, ConfigError>
pub fn from_env() -> Result<Self, ConfigError>
Build from the process environment. Thin wrapper over
Config::from_values; kept separate so the validation logic
stays testable without mutating process-wide env (which is
unsafe in Rust 2024).
§Errors
Returns ConfigError if MBA_PASSWORD is empty or MBA_UPSTREAM
is not a valid absolute HTTP(S) URL.
Sourcepub fn from_values(password: &str, upstream: &str) -> Result<Self, ConfigError>
pub fn from_values(password: &str, upstream: &str) -> Result<Self, ConfigError>
Build and validate from explicit values (pure, env-free).
§Examples
assert!(Config::from_values("hunter2", "http://app:2001").is_ok());
assert!(Config::from_values("", "http://app:2001").is_err()); // No password.
assert!(Config::from_values("hunter2", "/relative").is_err()); // No host.§Errors
Returns ConfigError::MissingPassword for an empty password, or
ConfigError::MissingUpstream / ConfigError::InvalidUpstream
if the upstream is not a valid absolute HTTP(S) URL.
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
Mutably borrows from an owned value. Read more