Change Wrapper.splitter from T: WordSplitter to Box<dyn WordSplitter>#206
Merged
Change Wrapper.splitter from T: WordSplitter to Box<dyn WordSplitter>#206
Wrapper.splitter from T: WordSplitter to Box<dyn WordSplitter>#206Conversation
9ac9b11 to
62c643c
Compare
Before, the Wrapper would be generic in the type of WordSplitter used. This meant that Wrapper<NoHyphenation> would be a different type than Wrapper<HyphenSplitter>. The result is that you need to fix the type of WordSplitter at compile time. This makes it hard to make interactive programs, something which was raised in #178. Making splitter a Box<dyn WordSplitter> makes the field less special. We can therefore simplify the API by removing the with_splitter constructor. The performance is unchanged by this, even when testing with the hyphenation feature enabled.
62c643c to
6810a97
Compare
Cryptjar
added a commit
to Cryptjar/textwrap
that referenced
this pull request
Oct 24, 2020
This commit reverts the internal changes of mgeisler#206, but keeps the public API compatible to what it introduced. Essetially by adding a default for the type parameter. However, now in addition to the dynamic dispatch by default, one may also explicitly use static dispatch by specifying the type parameter. This now allows to construct an `Options` instance in const/static context. Which is further facilitated by adding the const fns `new_const` and `with_splitter`. This change is actually backwards compatible with the previous commit, as seen by the unchanged examples and tests.
Cryptjar
added a commit
to Cryptjar/textwrap
that referenced
this pull request
Oct 24, 2020
This commit reverts the internal changes of mgeisler#206, but keeps the public API compatible to what it introduced. Essetially by adding a default for the type parameter. However, now in addition to the dynamic dispatch by default, one may also explicitly use static dispatch by specifying the type parameter. This now allows to construct an `Options` instance in const/static context. Which is further facilitated by adding the const fns `new_const` and `with_splitter`. This change is actually backwards compatible with the previous commit, as seen by the unchanged examples and tests.
Cryptjar
added a commit
to Cryptjar/textwrap
that referenced
this pull request
Oct 30, 2020
This commit reverts the internal changes of mgeisler#206, but keeps the public API compatible to what it introduced. Essetially by adding a default for the type parameter. However, now in addition to the dynamic dispatch by default, one may also explicitly use static dispatch by specifying the type parameter. This now allows to construct an `Options` instance in const/static context. Which is further facilitated by adding the const fn `with_splitter`. Also, since `Options` now may be some specific type the `Clone` derive is added again. So when `S` is `Clone` then `Options` is `Clone` too. This change is actually backwards compatible with the previous commit, as seen by the unchanged examples and tests.
Cryptjar
added a commit
to Cryptjar/textwrap
that referenced
this pull request
Nov 9, 2020
This commit reverts the internal changes of mgeisler#206, but keeps the public API compatible to what it introduced. Essetially by adding a default for the type parameter. However, now in addition to the dynamic dispatch by default, one may also explicitly use static dispatch by specifying the type parameter. This now allows to construct an `Options` instance in const/static context. Which is further facilitated by adding the const fn `with_splitter`. Also, since `Options` now may be some specific type the `Clone` derive is added again. So when `S` is `Clone` then `Options` is `Clone` too. This change is actually backwards compatible with the previous commit, as seen by the unchanged examples and tests.
Cryptjar
added a commit
to Cryptjar/textwrap
that referenced
this pull request
Nov 9, 2020
This commit reverts the internal changes of mgeisler#206, but keeps the public API compatible to what it introduced. Essetially by adding a default for the type parameter. However, now in addition to the dynamic dispatch by default, one may also explicitly use static dispatch by specifying the type parameter. This now allows to construct an `Options` instance in const/static context. Which is further facilitated by adding the const fn `with_splitter`. Also, since `Options` now may be some specific type the `Clone` derive is added again. So when `S` is `Clone` then `Options` is `Clone` too. This change is actually backwards compatible with the previous commit, as seen by the unchanged examples and tests.
Wrapper.splitter from T: WordSplitter to Box<dyn WordSplitter>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Before, the
Wrapperwould be generic in the type ofWordSplitterused. This meant thatWrapper<NoHyphenation>would be a different type thanWrapper<HyphenSplitter>.The result is that you need to fix the type of
WordSplitterat compile time. This makes it hard to make interactive programs, something which was raised in #178.Making splitter a
Box<dyn WordSplitter>makes the field less special. We can therefore simplify the API by removing thewith_splitterconstructor.The performance is unchanged by this, even when testing with the
hyphenationfeature enabled.