pub struct ConfigBuilder<'a> { /* private fields */ }Expand description
A builder to create a Config
The ConfigBuilder starts with the default Config and can create the Config with the
ConfigBuilder::build method as const at compile time.
§Examples
use fundu_core::config::{Config, ConfigBuilder};
use fundu_core::time::TimeUnit;
const CONFIG: Config = ConfigBuilder::new()
.default_unit(TimeUnit::MilliSecond)
.disable_fraction()
.build();
assert_eq!(CONFIG.default_unit, TimeUnit::MilliSecond);
assert_eq!(CONFIG.disable_fraction, true);Implementations§
Source§impl<'a> ConfigBuilder<'a>
impl<'a> ConfigBuilder<'a>
Sourcepub const fn allow_time_unit_delimiter(self) -> Self
pub const fn allow_time_unit_delimiter(self) -> Self
Allow a Delimiter between the number and time unit (Default: None)
See also the documentation of Config::allow_time_unit_delimiter
§Examples
use fundu_core::config::{Config, ConfigBuilder};
const CONFIG: Config = ConfigBuilder::new().allow_time_unit_delimiter().build();
assert!(CONFIG.allow_time_unit_delimiter);or with another whitespace definition for the inner_delimiter
use fundu_core::config::{Config, ConfigBuilder};
const CONFIG: Config = ConfigBuilder::new()
.allow_time_unit_delimiter()
.inner_delimiter(|byte| byte == b' ')
.build();
assert!(CONFIG.allow_time_unit_delimiter);
assert!((CONFIG.inner_delimiter)(b' '));Sourcepub const fn default_unit(self, time_unit: TimeUnit) -> Self
pub const fn default_unit(self, time_unit: TimeUnit) -> Self
The TimeUnit the parser applies if no time unit was given (Default: TimeUnit::Second)
See also the documentation of Config::default_unit
§Examples
use fundu_core::config::{Config, ConfigBuilder};
use fundu_core::time::TimeUnit;
const CONFIG: Config = ConfigBuilder::new()
.default_unit(TimeUnit::MilliSecond)
.build();
assert_eq!(CONFIG.default_unit, TimeUnit::MilliSecond);Sourcepub const fn disable_exponent(self) -> Self
pub const fn disable_exponent(self) -> Self
Disable parsing an exponent (Default: false)
See also the documentation of Config::disable_exponent
§Examples
use fundu_core::config::{Config, ConfigBuilder};
const CONFIG: Config = ConfigBuilder::new().disable_exponent().build();
assert_eq!(CONFIG.disable_exponent, true);Sourcepub const fn disable_fraction(self) -> Self
pub const fn disable_fraction(self) -> Self
Disable parsing a fraction (Default: false)
See also the documentation of Config::disable_fraction
§Examples
use fundu_core::config::{Config, ConfigBuilder};
const CONFIG: Config = ConfigBuilder::new().disable_fraction().build();
assert_eq!(CONFIG.disable_fraction, true);Sourcepub const fn disable_infinity(self) -> Self
pub const fn disable_infinity(self) -> Self
Disable parsing infinity (Default: false)
See also the documentation of Config::disable_infinity
§Examples
use fundu_core::config::{Config, ConfigBuilder};
const CONFIG: Config = ConfigBuilder::new().disable_infinity().build();
assert_eq!(CONFIG.disable_infinity, true);Sourcepub const fn number_is_optional(self) -> Self
pub const fn number_is_optional(self) -> Self
Make a number in the input string optional (Default: false)
See also the documentation of Config::number_is_optional
§Examples
use fundu_core::config::{Config, ConfigBuilder};
const CONFIG: Config = ConfigBuilder::new().number_is_optional().build();
assert_eq!(CONFIG.number_is_optional, true);Sourcepub const fn allow_negative(self) -> Self
pub const fn allow_negative(self) -> Self
Allow parsing negative durations (Default: false)
See also the documentation of Config::allow_negative
§Examples
use fundu_core::config::{Config, ConfigBuilder};
const CONFIG: Config = ConfigBuilder::new().allow_negative().build();
assert_eq!(CONFIG.allow_negative, true);Sourcepub const fn parse_multiple(self, conjunctions: Option<&'a [&'a str]>) -> Self
pub const fn parse_multiple(self, conjunctions: Option<&'a [&'a str]>) -> Self
This setting allows multiple durations in the source string (Default: None)
See also the documentation of Config::allow_multiple and
Config::conjunctions.
§Examples
use fundu_core::config::{Config, ConfigBuilder, Delimiter};
const CONJUNCTIONS: &[&str] = &["and", ",", "also"];
const CONFIG: Config = ConfigBuilder::new()
.parse_multiple(Some(CONJUNCTIONS))
.build();
assert_eq!(CONFIG.conjunctions, Some(CONJUNCTIONS));Sourcepub const fn allow_ago(self) -> Self
pub const fn allow_ago(self) -> Self
Allow the ago keyword delimited by a Delimiter to indicate a negative duration
(Default: None)
See also the documentation of Config::allow_ago. Setting allow_ago with this
method also enables parsing negative durations like with ConfigBuilder::allow_negative
§Examples
use fundu_core::config::{Config, ConfigBuilder};
const CONFIG: Config = ConfigBuilder::new().allow_ago().build();
assert!(CONFIG.allow_ago);
assert!(CONFIG.allow_negative);Sourcepub const fn allow_sign_delimiter(self) -> Self
pub const fn allow_sign_delimiter(self) -> Self
Allow a Delimiter between the sign and a number, time keyword … (Default: None)
See also the documentation of Config::allow_sign_delimiter
§Examples
use fundu_core::config::{Config, ConfigBuilder};
const CONFIG: Config = ConfigBuilder::new().allow_sign_delimiter().build();
assert!(CONFIG.allow_sign_delimiter);Sourcepub const fn inner_delimiter(self, delimiter: Delimiter) -> Self
pub const fn inner_delimiter(self, delimiter: Delimiter) -> Self
Set the inner Delimiter to something different then the default
u8::is_ascii_whitespace
Where the inner delimiter occurs, depends on other options:
ConfigBuilder::allow_sign_delimiter: Between the sign and the numberConfigBuilder::allow_time_unit_delimiter: Between the number and the time unitConfigBuilder::allow_ago: Between the time unit and theagokeyword- If
NumbersLikenumerals are used, between the numeral and the time unit
See also the documentation of Config::inner_delimiter
§Examples
use fundu_core::config::{Config, ConfigBuilder};
const CONFIG: Config = ConfigBuilder::new()
.inner_delimiter(|byte| byte == b'#')
.build();
assert!((CONFIG.inner_delimiter)(b'#'));Sourcepub const fn outer_delimiter(self, delimiter: Delimiter) -> Self
pub const fn outer_delimiter(self, delimiter: Delimiter) -> Self
Set the outer Delimiter to something different then the default
u8::is_ascii_whitespace
The outer delimiter is used to separate multiple durations like in 1second 1minute and is
therefore used only if Config::allow_multiple is set to true. If
conjunctions are set, this delimiter also separates the conjunction from the durations
(like in 1second and 1minute)
See also the documentation of Config::outer_delimiter
§Examples
use fundu_core::config::{Config, ConfigBuilder};
const CONFIG: Config = ConfigBuilder::new()
.outer_delimiter(|byte| byte == b'#')
.build();
assert!((CONFIG.outer_delimiter)(b'#'));Trait Implementations§
Source§impl<'a> Clone for ConfigBuilder<'a>
impl<'a> Clone for ConfigBuilder<'a>
Source§fn clone(&self) -> ConfigBuilder<'a>
fn clone(&self) -> ConfigBuilder<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more