-
Notifications
You must be signed in to change notification settings - Fork 45
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
Simplify Options
by removing generic type parameters
#438
Merged
Conversation
This file contains 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
This constructor was a left over from back when `Options` had a single `WordSplitter` generic type parameter. Now that we have several generic type parameters, having this constructor make one parameter different from the others (for no good reason). The `with_word_splitter` method was const, so we now lose the ability to construct `Options` with a non-default `WordSplitter` in a const context. If this is important to you, please get in contact so we can look at making the builder methods const instead.
This test helped me confirm that the many traits worked the right way, e.g., that dynamic dispatch was available when needed. However, I will be removing the traits in the next few commits and thus we don’t need the test any longer.
We don’t need this test with the simpler types: the types tell us directly that cloning works.
mgeisler
force-pushed
the
remove-traits
branch
from
February 20, 2022 19:07
7046846
to
3b7ea32
Compare
mgeisler
changed the title
Simplify
Simplify Feb 20, 2022
Options
by removing traitsOptions
by removing generic type parameters
mgeisler
force-pushed
the
remove-traits
branch
2 times, most recently
from
February 20, 2022 19:20
db2b259
to
feb3171
Compare
This replaces the `WordSplitter` trait with an enum. The result is a simplified `Options` type: it has one less generic type parameter.
mgeisler
force-pushed
the
remove-traits
branch
2 times, most recently
from
February 26, 2022 09:11
6e926c4
to
1f6b65f
Compare
This replaces the `WordSeparator` trait with an enum. The result is a simplified `Options` type: it has one less generic type parameter.
This replaces the `WordAlgorithm` trait with an enum. The result is a simplified `Options` type: it has one less generic type parameter.
There are no trait objects now, only concrete types.
mgeisler
force-pushed
the
remove-traits
branch
2 times, most recently
from
February 26, 2022 10:15
2d62107
to
2d2b02e
Compare
Before, the `OptimalFit` struct was implementing the old `WrapAlgorithm` trait. It therefore made sense to say that the struct (with its penalties) _were_ the wrapping algorithm. However, now that we have a `WrapAlgorithm::OptimalFit` enum variant, the struct should be renamed to reflect its purpose.
mgeisler
force-pushed
the
remove-traits
branch
from
February 26, 2022 10:21
2d2b02e
to
2af9473
Compare
This was referenced Feb 26, 2022
Merged
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.
This PR removes the three generic type parameters from the
Options
struct. Before we hadand now we simply have
which is much easier on the eyes. A consequence of this is that the function signatures of
wrap
,fill
, etc are simplified as well. The old functionality is kept intact and there areCustom
enum variants which accept a function pointer for quick and easy extensions (though the functions cannot borrow anything — please let me know if this is a concern).The change here is almost performance neutral with only a 1-2% regression:
Somewhat surprisingly, this PR is also nearly neutral with regards to the binary size with one configuration taking 4 KB more than before:
As soon as we enable the default features, the size difference disappears.