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.
In #219, the type parameter for
Options
was relaxed to?Sized
, which means thatOptions<T>
can be a dynamically-sized type by usingdyn WordSplitter
as the type parameter. This allows code to freely assign both boxed and unboxedWordSplitter
s to the same variable:In both cases, dynamic dispatch would be used at runtime. This was called “proper outer boxing” in #219 and #215.
By only boxing the word splitter (so-called “inner boxing”), the outer layer of indirection can be removed:
This also used dynamic dispatch at runtime.
Static dispatching was also possible by using a fixed type. Trying to change the word splitter type is a compile time error:
In order to add a trait for the
WrapAlgorithm
enum (see #325), we’re now removing the?Sized
bound on theWordSplitter
type parameter. This makes the first block above a compile time error and you must now choose upfront between boxed and unboxed word splitters. If you choose a boxed word splitter (second example), then you get dynamic dispatchand can freely change the word splitter at runtime. If you choose an unboxed wordsplitter, you get static dispatch and cannot change the word splitter later.
This change seems necessary since we will be adding more type parameters to the
Options
struct: one for the wrapping algorithm and one for how we find words (splitting by space or by the full Unicode line breaking algorithm).Since both dynamic and static dispatch remains possible, this change should not fundamentally change the expressive power of the library.