Two different modes:
- Serialize the full Config object. This is useful as
`Config::default().to_toml()` to output a rustfmt.toml with defaults
(#317).
- Serialize only the options that have been accessed. This could be
useful to output a minimal rustfmt.toml for a project. (If the
default value of any unused config item changes, you'll then get the
new default when you come to use it).
This commit doesn't expose this anywhere - deciding a sensible CLI is a
bit trickier.
This commit also has very simple error reporting (Result<String,
String>) - once the CLI is decided, a more sensible method of reporting
errors might become obvious.
Required by #865. This doesn't introduce any method to view which
parameters are accessed.
We record which config items are accessed even if we don't intend to
output them, as we assume it will be a relatively cheap operation.
As the comments in the issue state: it appears to work now, so this test
should just stop any regressions.
The second example in the issue description will format to the first,
which is then a fixed-point.
Preparation for #865, which proposes adding a flag which outputs which
config options are used during formatting.
This PR should not make any difference to functionality. A lot of this
was search-and-replace.
Some areas worthy of review/discussion:
- The method for each config item returns a clone of the underlying
value. We can't simply return an immutable reference, as lots of
places in the code expect to be able to pass the returned value as
`bool` (not `&bool). It would be nice if the `bool` items could
return a copy, but the more complex types a borrowed reference... but
unfortunately, I couldn't get the macro to do this.
- A few places (mostly tests and `src/bin/rustfmt.rs`) were overriding
config items by modifying the fields of the `Config` struct directly.
They now use the existing `override_value()` method, which has been
modified to return a `Result` for use by `src/bin/rustfmt.rs`. This
benefits of this are that the complex `file_lines` and `write_mode`
strings are now parsed in one place (`Config.override_value`) instead
of multiple. The disadvantages are that it moves the compile-time
checks for config names to become run-time checks.