Skip to main content

ParsableConfigValue

Trait ParsableConfigValue 

Source
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§

Source

fn parse_user_value(value: &str) -> Option<Self>

Source

fn to_config_string(&self) -> String

Serialize this value to a string that can be parsed back via parse_user_value.

Provided Methods§

Source

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.

Source

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

Source§

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.

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.

Implementors§