-
Notifications
You must be signed in to change notification settings - Fork 54
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
Add StrExt: to_lowercase_smolstr & friends #69
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading through #68, I would've expected these to be just inherent methods on SmolStr
that would shadow the str
versions. I am not a big fan of extension traits, and the implementation exposed here could be implemented by downstream users a like (unlike the inherent methods making use of the hidden repr to clone accordingly)
That would be a breaking change I think, as code that currently compiles to return The other advantage of the extension trait is these methods can be called on
This isn't true as the trait is sealed. |
An example of why having
So this could actually allocate more than just using str::to_lowercase. Whereas StrExt::to_lowercase_smolstr would only allocate 0-1 times here. There are tons of methods manipulating strings -> &str that this applies to.
🤔 or perhaps you meant that this logic doesn't need to be in the crate because it can be implemented outside? That is true, but this is generally useful code that would fit here for a similar reason |
Well we can always bump the minor version, that's not an issue.
That's fair, I just got a bit confused as the issue you opened seem to imply the things that what I wrote here, instead of what the PR tackles 😅 (I do think there is value in the inherent methods nevertheless, as that would be better when going from
That was what I meant yes. I'll merge it for now as it seems reasonable given the perf implications. Thanks! |
Yep i changed my outlook after raising the issue and actually implementing. Sorry for the confusion. I think it would be possible to add specialised For small strings i think StrExt is already optimal as is. |
Add
smol_str::StrExt
trait providing methods forstr
s producingSmolStr
s.to_lowercase_smolstr
to_uppercase_smolstr
to_ascii_lowercase_smolstr
to_ascii_uppercase_smolstr
These allow case conversion of small strings sans allocation.
The trait is sealed to allow adding additional methods in future without breaking semver.
Resolves #68