Skip to main content

ConfigBuilder

Struct ConfigBuilder 

Source
pub struct ConfigBuilder { /* private fields */ }
Expand description

Build a config.

This will build a config from the input resolvers and then validate and output the config.

Implementations§

Source§

impl ConfigBuilder

Source

pub fn new() -> Self

Prepare a new builder.

Source

pub fn add_string_resolver( self, key: impl TryInto<FieldKey, Error = Error>, pattern: Option<&str>, ) -> Result<Self, Error>

Add a string resolver.

The string resolver is the simplest type of resolver. It doesn’t have much context other than this is a string of characters, and maybe the expected shape of the string (if the regex pattern is specified). The pattern, if specified, must follow these rules:

  • It must be as non-greedy as possible (for example, use \w+? instead of \w+). This prevents the pattern from consuming more than it should.
  • It must not use any anchors such as ^ or $. When the system builds the internal regex from the supplied regexes, it will automatically add the anchors to make the path query more specific.
  • It must not use capturing groups. The internal regex may create capture groups when extracting the field values from paths.
Source

pub fn add_integer_resolver( self, key: impl TryInto<FieldKey, Error = Error>, padding: u8, ) -> Result<Self, Error>

Add an integer resolver.

Integer resolvers will create integers with zero padding. When the integers are being extracted from a path, then only numbers with a minimum number of characters based on the padding are considered valid. For example, if the padding is 3 then 1 and 12 are invalid, but 001, 012, 123, and 1234 are valid.

Source

pub fn add_path_item(self, args: PathItemArgs) -> Result<Self, Error>

Add a path item.

Path items are parts of paths that are either fully resolved (contain no placeholders), or partially resolved (contains placeholders). See PathItemArgs for more information.

Source

pub fn build(self) -> Result<Config, Error>

Build the config from the builder.

§Errors
  • Path items must not form a circular dependency through the parent key.
  • If a path item defines a parent, the parent must be defined in the current builder.
  • If the path parts have placeholders, then the syntax must be correct. However, a placeholder does not need to reference a resolver (it will assume a string resolver).

Trait Implementations§

Source§

impl Debug for ConfigBuilder

Source§

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

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

impl Default for ConfigBuilder

Source§

fn default() -> ConfigBuilder

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

Auto Trait Implementations§

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> 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, 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.