Struct ConfigBuilder

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

Source

pub const fn new() -> Self

Create a new ConfigBuilder with the default Config as base.

Note the ConfigBuilder can build the Config as const at compile time if needed.

§Examples
use fundu_core::config::ConfigBuilder;

let config = ConfigBuilder::new().allow_negative().build();

assert_eq!(config.allow_negative, true);
Source

pub const fn build(self) -> Config<'a>

Build the Config with the configuration of this builder

§Examples
use fundu_core::config::{Config, ConfigBuilder};

const CONFIG: Config = ConfigBuilder::new().disable_fraction().build();

assert_eq!(CONFIG.disable_fraction, true);
Source

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' '));
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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));
Source

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);
Source

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);
Source

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:

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'#'));
Source

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>

Source§

fn clone(&self) -> ConfigBuilder<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for ConfigBuilder<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Default for ConfigBuilder<'a>

Source§

fn default() -> ConfigBuilder<'a>

Returns the “default value” for a type. Read more
Source§

impl<'a> PartialEq for ConfigBuilder<'a>

Source§

fn eq(&self, other: &ConfigBuilder<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Eq for ConfigBuilder<'a>

Source§

impl<'a> StructuralPartialEq for ConfigBuilder<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for ConfigBuilder<'a>

§

impl<'a> RefUnwindSafe for ConfigBuilder<'a>

§

impl<'a> Send for ConfigBuilder<'a>

§

impl<'a> Sync for ConfigBuilder<'a>

§

impl<'a> Unpin for ConfigBuilder<'a>

§

impl<'a> UnwindSafe for ConfigBuilder<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.