-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pretty-print functionality #44
Add pretty-print functionality #44
Conversation
Users can now provide various options for formatting output: Spaces around `=` or not, the number of blank lines between sections, and the number of spaces used to indent multi-line values.
Looks good! Can you rebase this to |
Thanks! I'm not sure I understand the need for rebasing - I believe the branch is up date with the latest changes on WRT using I have looked into this, and it is indeed possible to initialize collections with I changed the #[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "derive_builder", derive(Builder), builder(default))]
#[non_exhaustive]
pub struct Ini {
#[cfg_attr(feature = "derive_builder", builder(setter(each(name = "set_value"))))]
map: Map<String, Map<String, Option<String>>>,
default_section: std::string::String,
comment_symbols: Vec<char>,
delimiters: Vec<char>,
boolean_values: HashMap<bool, Vec<String>>,
case_sensitive: bool,
multiline: bool,
}
impl Default for Ini {
fn default() -> Self {
let defaults = IniDefault::default();
Self {
map: Map::new(),
default_section: defaults.default_section,
comment_symbols: defaults.comment_symbols,
delimiters: defaults.delimiters,
boolean_values: defaults.boolean_values,
case_sensitive: defaults.case_sensitive,
multiline: defaults.multiline,
}
}
} After this I can now use the builder pattern to build an let my_config = IniBuilder::default()
.set_value(
("section1".into(),
Map::from(
[
("key1".into(), Some("value1".into())),
("key2".into(), Some("value2".into())),
("key3".into(), Some("value3".into())),
]
)
)
)
.set_value(
("section2".into(),
Map::from(
[
("key4".into(), Some("value4".into())),
("key5".into(), Some("value5".into())),
("key6".into(), Some("value6".into())),
]
)
)
)
.build()?;
let ini_string = my_config.writes(); If I don't want to initialize the map, but, e.g., just want to enable multiline support, I can just write let my_config2 = IniBuilder::default()
.multiline(true)
.build()?; Maybe we could make it a bit easier to initialize the map with a macro. Should we go this way? |
I think this is more complicated than how it should be, I assume we could have an easy way to extend serde support but not really (from this angle). Here are my present thoughts:
Let's tackle |
I have been thinking more or less the same after I posted the example. I agree 100% with your thoughts. I will make your suggested changes tonight (CET, don't know which timezone you're in 😄 ). |
Remove the build pattern support and its corresponding dependency on derive-builder. Add tests. Update method documentation and README.
I pushed changes to reflect what we agreed upon. Also added some tests and updated the README and the docs in |
I made some slight changes to your implementation, mostly to help with creating a new |
Looks good to me - even though the |
I take it that you handle bumping the version number to what you see fit? |
Yeah, will handle that in a separate PR. |
With the changes in this PR, users can now provide various options for formatting output: Spaces around
=
or not, the number of blank lines between sections, and the number of spaces used to indent multi-line values.I have not added tests for the new functionality yet, since I would like to get feedback on the ideas and principles used before I proceed.