LukasKalbertodt/confique

Means to customize FormatOptions

graelo opened this issue · 2 comments

Hi,

I'd like to customize the template output for toml, but because FormatOptions and toml::FormatOptions (same for yaml and json5) are non_exhaustive and only implement the Default trait, it looks like I can't instantiate these structs easily. Right now, the only way I can think of is creating a new trait and implementing it for these structs.

If I'm not missing something, would you consider adding each one a function new allowing the user to pass parameters. I realize that maybe it would lead to a breaking change if you add new fields to these structs. Maybe a builder pattern?

Thanks!

Mh I'm not sure I understand. The intended way is for you to use the Default impl with the struct init syntax:

let options= toml::FormatOptions {
    indent: 4,
    .. Default::default()
};

What's wrong with that? But I agree it could be explained better in the docs.

Ah, I had completely forgotten about this way. Perfect, thanks! (and sorry for the noise)