Skip to content

Commit

Permalink
feat: forbid creating IniDefault using struct expression
Browse files Browse the repository at this point in the history
This ensures that new fields can be added to it without it being
a breaking change.
  • Loading branch information
vthib committed Oct 14, 2021
1 parent b9cbdea commit 48604e1
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions src/ini.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub struct Ini {
///let mut config2 = Ini::new_from_defaults(default); // default gets consumed
///```
#[derive(Debug, Clone, Eq, PartialEq)]
#[non_exhaustive]
pub struct IniDefault {
///Denotes the default section header name.
///## Example
Expand Down Expand Up @@ -145,16 +146,9 @@ impl Ini {
///use configparser::ini::Ini;
///use configparser::ini::IniDefault;
///
///let default = IniDefault {
/// default_section: "default".to_owned(),
/// comment_symbols: vec![';'],
/// delimiters: vec!['='],
/// boolean_values: [
/// (true, vec!["true", "yes", "t", "y", "on", "1"].iter().map(|&s| s.to_owned()).collect()),
/// (false, vec!["false", "no", "f", "n", "off", "0"].iter().map(|&s| s.to_owned()).collect()),
/// ].iter().cloned().collect(),
/// case_sensitive: true,
///};
///let mut default = IniDefault::default();
///default.comment_symbols = vec![';'];
///default.delimiters = vec!['='];
///let mut config = Ini::new_from_defaults(default.clone());
///// Now, load as usual with new defaults:
///let map = config.load("tests/test.ini").unwrap();
Expand Down Expand Up @@ -199,16 +193,9 @@ impl Ini {
///use configparser::ini::IniDefault;
///
///let mut config = Ini::new();
///let default = IniDefault {
/// default_section: "default".to_owned(),
/// comment_symbols: vec![';', '#'],
/// delimiters: vec!['=', ':'],
/// boolean_values: [
/// (true, vec!["true", "yes", "t", "y", "on", "1"].iter().map(|&s| s.to_owned()).collect()),
/// (false, vec!["false", "no", "f", "n", "off", "0"].iter().map(|&s| s.to_owned()).collect()),
/// ].iter().cloned().collect(),
/// case_sensitive: true,
///}; // This is equivalent to ini_cs() defaults
///let mut default = IniDefault::default();
///default.case_sensitive = true;
///// This is equivalent to ini_cs() defaults
///config.load_defaults(default.clone());
///assert_eq!(config.defaults(), default);
///```
Expand Down

0 comments on commit 48604e1

Please sign in to comment.