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 and SocketAddr are 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. Delegates to the same pure
validation as Config::from_values so tests do not have to mutate
process-wide env (which is unsafe in Rust 2024).
§Errors
Returns ConfigError if MBA_ADDRESS is not a valid non-zero IP
socket address, 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. The bind
address uses the default 0.0.0.0:8000.
Sourcepub fn bind_address(&self) -> SocketAddr
pub fn bind_address(&self) -> SocketAddr
Validated IP socket address the service listens on.