Skip to content

Commit

Permalink
marked-yaml: Ergonomics for LoaderOptions
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
  • Loading branch information
kinnison committed Mar 26, 2024
1 parent a95cad3 commit 79c0834
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
1 change: 1 addition & 0 deletions marked-yaml/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub enum LoadError {
}

/// Options for loading YAML
#[derive(Debug, Default)]
pub struct LoaderOptions {
/// If true, duplicate keys in mappings will cause an error. If false,
/// the last key will be used.
Expand Down
13 changes: 2 additions & 11 deletions marked-yaml/src/spanned_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,13 +491,7 @@ pub fn from_yaml<T>(source: usize, yaml: &str) -> Result<T, FromYamlError>
where
T: DeserializeOwned,
{
from_yaml_with_options(
source,
yaml,
LoaderOptions {
error_on_duplicate_keys: false,
},
)
from_yaml_with_options(source, yaml, LoaderOptions::default())
}

/// Deserialize some YAML into the requisite type
Expand All @@ -516,10 +510,7 @@ where
/// struct Greeting {
/// hello: Spanned<String>,
/// }
/// let options = LoaderOptions {
/// error_on_duplicate_keys: true,
/// };
/// let greets: Greeting = marked_yaml::from_yaml_with_options(0, YAML, options).unwrap();
/// let greets: Greeting = marked_yaml::from_yaml_with_options(0, YAML, LoaderOptions::default()).unwrap();
/// let start = greets.hello.span().start().unwrap();
/// assert_eq!(start.line(), 1);
/// assert_eq!(start.column(), 8);
Expand Down

0 comments on commit 79c0834

Please sign in to comment.