pub trait ParsableConfigValue: Debug + Sized {
// Required methods
fn parse_user_value(value: &str) -> Option<Self>;
fn to_config_string(&self) -> String;
// Provided methods
fn try_update_in_place(&mut self, value: &str) -> bool { ... }
fn parse_config_value(
variable_name: &str,
value: Option<String>,
default: Self,
) -> Self { ... }
}Expand description
A trait to control how a value is parsed from an environment string or other config source
if it’s present. Also provides serialization back to a string representation that
roundtrips with parse_user_value.
Required Methods§
fn parse_user_value(value: &str) -> Option<Self>
Sourcefn to_config_string(&self) -> String
fn to_config_string(&self) -> String
Serialize this value to a string that can be parsed back via parse_user_value.
Provided Methods§
Sourcefn try_update_in_place(&mut self, value: &str) -> bool
fn try_update_in_place(&mut self, value: &str) -> bool
Try to update this value in place from a string. Returns true on success.
The default implementation delegates to parse_user_value, but types like
ConfigEnum override this to use context-aware validation.
Sourcefn parse_config_value(
variable_name: &str,
value: Option<String>,
default: Self,
) -> Self
fn parse_config_value( variable_name: &str, value: Option<String>, default: Self, ) -> Self
Parse the value, returning the default if it can’t be parsed or the string is empty.
Issue a warning if it can’t be parsed.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl ParsableConfigValue for bool
impl ParsableConfigValue for bool
fn parse_user_value(value: &str) -> Option<Self>
fn to_config_string(&self) -> String
Source§impl ParsableConfigValue for Duration
Implement proper parsing for Duration types as well.
impl ParsableConfigValue for Duration
Implement proper parsing for Duration types as well.
Now the following suffixes are supported: s, ms, us, ns, m, h, d, etc.; see the humantime crate for the full list.
fn parse_user_value(value: &str) -> Option<Self>
fn to_config_string(&self) -> String
Source§impl<T: ParsableConfigValue> ParsableConfigValue for Option<T>
Enable Option to allow the default value to be None if nothing is set and appear as
Some(Value) if the user specifies the value.
impl<T: ParsableConfigValue> ParsableConfigValue for Option<T>
Enable Option
fn parse_user_value(value: &str) -> Option<Self>
fn to_config_string(&self) -> String
Implementors§
impl ParsableConfigValue for ConfigEnum
impl ParsableConfigValue for TemplatedPathBuf
target_family=wasm only.