Skip to content

Commit

Permalink
loader: Make LoaderOptions a builder style struct
Browse files Browse the repository at this point in the history
To pave the way for future loader options without
having public fields all the time causing major version jumps,
we are taking the hit now to hide the fields and expose methods
for the various loader options.

Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
  • Loading branch information
kinnison committed Jun 6, 2024
1 parent 13cc9fd commit 8fec8a0
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions marked-yaml/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,26 @@ pub enum LoadError {
}

/// Options for loading YAML
///
/// Default options ([`LoaderOptions::default()`]) are:
///
/// - Permit duplicate keys
///
#[derive(Debug, Default)]
pub struct LoaderOptions {
/// If true, duplicate keys in mappings will cause an error. If false,
/// the last key will be used.
pub error_on_duplicate_keys: bool,
error_on_duplicate_keys: bool,
}

impl LoaderOptions {
/// Enable errors on duplicate keys
///
/// If enabled, duplicate keys in mappings will cause an error.
/// If disabled, the last key/value pair will be used.
pub fn error_on_duplicate_keys(self, enable: bool) -> Self {
Self {
error_on_duplicate_keys: enable,
}
}
}

impl Display for LoadError {
Expand Down

0 comments on commit 8fec8a0

Please sign in to comment.