[][src]Trait justconfig::validators::Range

pub trait Range<T: FromStr + PartialOrd + Display> {
    pub fn min(self, minimum: T) -> Result<TypedItem<T>, ConfigError>;
pub fn max(self, maximum: T) -> Result<TypedItem<T>, ConfigError>;
pub fn in_range<R: RangeBounds<T>>(
        self,
        range: R
    ) -> Result<TypedItem<T>, ConfigError>; }

Validates if a configuration value is within range by using the PartialOrd trait of the configuration target value.

Required methods

pub fn min(self, minimum: T) -> Result<TypedItem<T>, ConfigError>[src]

pub fn max(self, maximum: T) -> Result<TypedItem<T>, ConfigError>[src]

pub fn in_range<R: RangeBounds<T>>(
    self,
    range: R
) -> Result<TypedItem<T>, ConfigError>
[src]

Loading content...

Implementations on Foreign Types

impl<T: FromStr + PartialOrd + Display> Range<T> for Result<TypedItem<T>, ConfigError>[src]

pub fn min(self, minimum: T) -> Result<TypedItem<T>, ConfigError>[src]

Makes sure that the configuration value is at least the given value.

Uses the PartialOrd trait to make sure the configured value is less or equal the given value.

Example

defaults.set(conf.root().push_all(&["myitem"]), "4", "source info");
conf.add_source(defaults);

// This will panic because the value 4 is less than 5.
let value: i32 = conf.get(ConfPath::from(&["myitem"])).min(5).value().unwrap();

pub fn max(self, maximum: T) -> Result<TypedItem<T>, ConfigError>[src]

Makes sure that the configuration value is at most the given value.

Uses the PartialOrd trait to make sure the configured value is greater or equal to the given value.

Example

defaults.set(conf.root().push_all(&["myitem"]), "10", "source info");
conf.add_source(defaults);

// This will panic because the value 10 is more than 5.
let value: i32 = conf.get(ConfPath::from(&["myitem"])).max(5).value().unwrap();

pub fn in_range<R: RangeBounds<T>>(
    self,
    range: R
) -> Result<TypedItem<T>, ConfigError>
[src]

Makes sure that the configuration value is within a specified range.

Uses an implementaiton of the range trait to check if the configured value is within range.

Example

defaults.set(conf.root().push_all(&["myitem"]), "10", "source info");
conf.add_source(defaults);

// This will succeed because 10 is between 5 and 20.
let value: i32 = conf.get(ConfPath::from(&["myitem"])).in_range(5..=20).value().unwrap();

impl<T: FromStr + PartialOrd + Display> Range<T> for Result<StringItem, ConfigError> where
    T::Err: Error + 'static, 
[src]

Loading content...

Implementors

Loading content...