Refactor to use more idiomatic Rust patterns #14
Merged
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.
I thought I'd help contribute to the crate some more, since I'm using it for an application and it doesn't seem to get frequent contributions despite its high quality and utility.
This PR helps to refactor some code to use more idiomatic Rust patterns. Some of these are more opinionated than others, so feel free to comment on any you don't think are appropriate:
else
statements or check negations.matches!
statement, which is cleaner and slightly improves speed.unwrap_or()
tounwrap_or_else()
(which doesn't compute the enclosed value unless needed).Additionally, I do have some further questions/comments about the crate that I couldn't address myself:
into_str()
method in the modulestring
seems to have a few peculiarities:into_str()
, it returns aString
. Sincestr
is its own data type, this could lead to some confusion.std::mem::transmute()
to transform aCuredString(String)
into just aString
. This method could instead just return the inner value by doingself.0
. From what I can gather, any speed difference (if it exists) is negligible. The only drawback to this is that the function would not beconst
anymore, though I'm not sure when this would be used inconst
contexts ascure
is notconst
.I appreciate all the work you've done with this crate, and I hope that these contributions are helpful!