Skip to content

Commit

Permalink
Rename config options + non_exhaustive
Browse files Browse the repository at this point in the history
  • Loading branch information
ecton committed Oct 22, 2024
1 parent 0f740d4 commit d750303
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1456,7 +1456,7 @@ mod tests {
a: u32,
b: i32,
}
let config = Config::default().allow_implicit_map(true);
let config = Config::default().allow_implicit_map_at_root(true);
let parsed = config.deserialize::<BasicNamed>(r#"a: 1 b: -1"#).unwrap();
assert_eq!(parsed, BasicNamed { a: 1, b: -1 });
let parsed = config.deserialize::<BasicNamed>(r#"a: 1, b: -1,"#).unwrap();
Expand Down
9 changes: 5 additions & 4 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ impl<'s> Parser<'s> {
TokenKind::Comment(comment) => {
Ok(Event::new(token.location, EventKind::Comment(comment)))
}
_ if self.config.allow_implicit_map
_ if self.config.allow_implicit_map_at_root
&& matches!(
self.peek(),
Some(Token {
Expand Down Expand Up @@ -501,14 +501,15 @@ impl<'s> Iterator for Parser<'s> {
}

#[derive(Default, Debug, Clone, Copy)]
#[non_exhaustive]
pub struct Config {
pub allow_implicit_map: bool,
pub allow_implicit_map_at_root: bool,
pub include_comments: bool,
}

impl Config {
pub const fn allow_implicit_map(mut self, allow: bool) -> Self {
self.allow_implicit_map = allow;
pub const fn allow_implicit_map_at_root(mut self, allow: bool) -> Self {
self.allow_implicit_map_at_root = allow;
self
}

Expand Down
1 change: 1 addition & 0 deletions src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ where
}

#[derive(Default, Debug, Clone)]
#[non_exhaustive]
pub struct Config {
pub writer: writer::Config,
pub implicit_map_at_root: bool,
Expand Down
4 changes: 2 additions & 2 deletions src/tests/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fn roundtrip_implicit_map<T: Debug + Serialize + for<'de> Deserialize<'de> + Par
println!("{rendered}");
assert_eq!(rendered, check);
let restored: T = crate::parser::Config::default()
.allow_implicit_map(true)
.allow_implicit_map_at_root(true)
.deserialize(&rendered)
.expect("deserialization failed");
assert_eq!(&restored, value);
Expand All @@ -121,7 +121,7 @@ fn roundtrip_anonymous_structs<T: Debug + Serialize + for<'de> Deserialize<'de>
println!("{rendered}");
assert_eq!(rendered, check);
let restored: T = crate::parser::Config::default()
.allow_implicit_map(true)
.allow_implicit_map_at_root(true)
.deserialize(&rendered)
.expect("deserialization failed");
assert_eq!(&restored, value);
Expand Down
1 change: 1 addition & 0 deletions src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ enum MapState {
}

#[derive(Debug, Default, Clone)]
#[non_exhaustive]
pub enum Config {
#[default]
Compact,
Expand Down

0 comments on commit d750303

Please sign in to comment.