Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Wrapper.splitter from T: WordSplitter to Box<dyn WordSplitter> #206

Merged
merged 1 commit into from
Sep 15, 2020

Conversation

mgeisler
Copy link
Owner

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.

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.
@mgeisler mgeisler merged commit 276103d into master Sep 15, 2020
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.
@mgeisler mgeisler deleted the dynamic-dispatch branch December 29, 2020 00:02
@mgeisler mgeisler changed the title Change Wrapper.splitter from T: WordSplitter to Box<dyn WordSplitter> Change Wrapper.splitter from T: WordSplitter to Box<dyn WordSplitter> Apr 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant