pub struct EnvReader<F: Fn(&str) -> Option<String>> {
pub errors: Vec<String>,
/* private fields */
}Expand description
Reads configuration variables through a lookup function, collecting errors.
use mcp_server_core::config::EnvReader;
let mut env = EnvReader::new(|name: &str| (name == "PORT").then(|| "x".to_string()));
let port: u16 = env.parse("PORT", 8080);
let key = env.required("API_KEY");
assert_eq!((port, key), (8080, None));
assert_eq!(env.errors, ["PORT has an invalid value", "API_KEY is required"]);Fields§
§errors: Vec<String>Every problem found so far, as messages for the operator. They never contain secret values.
Implementations§
Source§impl EnvReader<fn(&str) -> Option<String>>
impl EnvReader<fn(&str) -> Option<String>>
Sourcepub fn from_process() -> Self
pub fn from_process() -> Self
Reads the process environment.
Source§impl<F: Fn(&str) -> Option<String>> EnvReader<F>
impl<F: Fn(&str) -> Option<String>> EnvReader<F>
Sourcepub fn optional(&mut self, name: &str) -> Option<String>
pub fn optional(&mut self, name: &str) -> Option<String>
The value of name, or of the file named by NAME_FILE; None when neither is set.
Sourcepub fn required(&mut self, name: &str) -> Option<String>
pub fn required(&mut self, name: &str) -> Option<String>
Like optional, recording “NAME is required” when unset.
Sourcepub fn secret_optional(&mut self, name: &str) -> Option<SecretString>
pub fn secret_optional(&mut self, name: &str) -> Option<SecretString>
optional as a secret that never prints.
Sourcepub fn secret_required(&mut self, name: &str) -> Option<SecretString>
pub fn secret_required(&mut self, name: &str) -> Option<SecretString>
required as a secret that never prints.
Sourcepub fn bool(&mut self, name: &str, default: bool) -> bool
pub fn bool(&mut self, name: &str, default: bool) -> bool
A boolean: 1, true, yes, on or 0, false, no, off, in any case.
Sourcepub fn parse<T: FromStr>(&mut self, name: &str, default: T) -> T
pub fn parse<T: FromStr>(&mut self, name: &str, default: T) -> T
Parses name, or returns default when unset or invalid (recording the error).
Sourcepub fn parse_optional<T: FromStr>(&mut self, name: &str) -> Option<T>
pub fn parse_optional<T: FromStr>(&mut self, name: &str) -> Option<T>
Parses name when set, recording an error when it does not parse.
Auto Trait Implementations§
impl<F> Forget for EnvReader<F>
impl<F> Freeze for EnvReader<F>where
F: Freeze,
impl<F> RefUnwindSafe for EnvReader<F>where
F: RefUnwindSafe,
impl<F> Send for EnvReader<F>where
F: Send,
impl<F> Sync for EnvReader<F>where
F: Sync,
impl<F> Unpin for EnvReader<F>where
F: Unpin,
impl<F> UnsafeUnpin for EnvReader<F>where
F: UnsafeUnpin,
impl<F> UnwindSafe for EnvReader<F>where
F: UnwindSafe,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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