Add ability to customize template keys #301
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR makes the
pos
andlen
fields ofProgressState
to havepub
visibility. I changed theper_sec
method ofProgressState
to return anf64
, and{per_sec}
in the template now rounds to an integer via theformat!
macro (rather than truncating by default), and is explicitly truncated in other places of the code. With this patch, you can now use.key(...)
method fromProgressStyle
to add a custom formatting function and template key. This PR also adds another example to show the usage of this feature.I also changed the
position
method to just be 2 separate methods for returning the position and length, because the usage beforehand whereposition()
was called before matching the template keys and then you would just reuse those for{pos}
and{len}
now seems like an anti-pattern with this hash map based approach.Also I had to remove
#[derive(Debug)]
forProgressStyle
because I was getting errors of "Debug
impl is not general enough" or something like that, and it didn't seem to be necessary anyway.