This commit removes some unnecessary code, such as an extra `String`
clone, unnecessary `return` statements, and an inherent `to_string`
function for the `Regex` wrapper.
A double-quote character considered as a string literal by the
compiler was also changed to a single-quote character, this time
considered as a character by the compiler, for some optimization.
Also a newline is added in order to improve code readablitiy.
Rules are now a separate struct, and the `rules` member of
`settings::Settings` is now a `Vec<settings::rule::Rule`.
Several elements were made private, now can be accessed through
dedicated methods
I didn't have to do it in two `replace` calls
Now I have to check if the rule has a or several corresponding
categories in the initial and final regex, find whether they have the
same amount of elements, and if so create rules that allow elements from
each category to be mapped 1:1
Rules are applied, however some bugs remain:
- The HashMap for rules should be replaced by a Vec so they can be
stored in order and not randomly
- For some reasons, the `%` is not removed from some rules in the
private function `update_rules` in the `Settings` struct.
- Make it so replacements between square brackets work correctly
Encoding and decoding of `settings::Settings` now handled in macros to
avoid code repetition. I also wish rewrite them both in a combined
macro that would either encode or decode the struct depending on how
it was called.
Replaced some log warnings with errors
Now if type extension is not valid, the code will still attempt to
decode it, first as JSON data, then as Yaml data. If both fail, then
an error is returned. For this, I added the Display trait to the
`settings::Settings` struct which allows the FromStr trait, and due
to conflicting implementation, I removed the From trait and
implemented manually the `from` method with the same signature -- the
struct just lacks the trait that comes with it.
Replaced lots of warns by errors
Filetype detection won’t return an error on unknown extension anymore,
but will return an `Other` value so it can be handled by other
functions not as an error already. See upcoming commits.
`write_file` now accepts as its second argument any type that
implements the `ToString` trait so that not only Strings will be
accepted but any type that can be turned into one.