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
impl ConfigBuilder
Sourcepub fn add_string_resolver(
self,
key: impl TryInto<FieldKey, Error = Error>,
pattern: Option<&str>,
) -> Result<Self, Error>
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.
Sourcepub fn add_integer_resolver(
self,
key: impl TryInto<FieldKey, Error = Error>,
padding: u8,
) -> Result<Self, Error>
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.
Sourcepub fn add_path_item(self, args: PathItemArgs) -> Result<Self, Error>
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.
Sourcepub fn build(self) -> Result<Config, Error>
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).