From d75030392c388bab2d6cbdaf26fbdad5c8e75790 Mon Sep 17 00:00:00 2001 From: Jonathan Johnson Date: Tue, 22 Oct 2024 10:00:11 -0700 Subject: [PATCH] Rename config options + non_exhaustive --- src/de.rs | 2 +- src/parser.rs | 9 +++++---- src/ser.rs | 1 + src/tests/serde.rs | 4 ++-- src/writer.rs | 1 + 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/de.rs b/src/de.rs index f9b1237..14925db 100644 --- a/src/de.rs +++ b/src/de.rs @@ -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::(r#"a: 1 b: -1"#).unwrap(); assert_eq!(parsed, BasicNamed { a: 1, b: -1 }); let parsed = config.deserialize::(r#"a: 1, b: -1,"#).unwrap(); diff --git a/src/parser.rs b/src/parser.rs index 498ddec..ee045bc 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -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 { @@ -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 } diff --git a/src/ser.rs b/src/ser.rs index 61c83a3..6946e68 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -457,6 +457,7 @@ where } #[derive(Default, Debug, Clone)] +#[non_exhaustive] pub struct Config { pub writer: writer::Config, pub implicit_map_at_root: bool, diff --git a/src/tests/serde.rs b/src/tests/serde.rs index 8699ac1..2c764ae 100644 --- a/src/tests/serde.rs +++ b/src/tests/serde.rs @@ -104,7 +104,7 @@ fn roundtrip_implicit_map 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); @@ -121,7 +121,7 @@ fn roundtrip_anonymous_structs 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); diff --git a/src/writer.rs b/src/writer.rs index 48de2a7..23e9481 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -356,6 +356,7 @@ enum MapState { } #[derive(Debug, Default, Clone)] +#[non_exhaustive] pub enum Config { #[default] Compact,