Rewrite to support generic Display types inside of ANSIString #79
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.
Motivation here was to make ANSIString work with arbitrary Display
types such that values don’t need to be first converted into a String.
For example, in the past one would have to write something along the
lines of:
This of course works but results in three String allocations. Those
can now be avoided since ANSIString can take any Display type and
postpone formatting to when the entire string is formatted:
Adding this feature lead to a rabbit hole of changing a lot of other
interfaces around ANSIString type.
Most notably, ANSIGenericString and ANSIByteString types no longer
exists. ANSIString is now the only type. Implementation of Display
trait and write_to method are now limited by the bounds on the generic
argument rather than on the type being ANSIString or ANSIByteString.
Similarly, there’s now just one ANSIStrings type which points at
a slice of strings.
Furthermore, util::substring now works on generic types and doesn’t
perform allocations on its own. E.g. when doing a substring over
Strings or Cows, the resulting substring borrows from the underlying
strings.
Lastly, how strings and bytes are written out has been completely
refactored. This is just an internal change though not observable by
the user.