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

Add StrExt::replace_smolstr, replacen_smolstr #72

Merged
merged 1 commit into from
Apr 18, 2024

Conversation

alexheretic
Copy link
Contributor

Add StrExt::replace_smolstr, StrExt::replacen_smolstr.

This is useful to avoid allocation on small strings, e.g:

let result = "foo-bar_baz".replace_smolstr("-", "_");
assert_eq!(result, "foo_bar_baz");
assert!(!result.is_heap_allocated());

Impl adapted from std str::replacen.

One undesirable difference from std is from uses Pattern in str::replace but this is not stable and can't be used here. However, I still think this version with from: &str is quite useful & worth having. Also if/when Pattern stabilizes we can start using it as a non-breaking change, since &str will implement it.

Note: While not needed for this PR this kind of usage is an example of why #70 would be useful for external use.

@alexheretic
Copy link
Contributor Author

@Veykril did you get a chance to look at this, any issues?

@Veykril
Copy link
Member

Veykril commented Apr 18, 2024

Ah sorry, I missed this. Sounds reasonable

@Veykril Veykril merged commit 1e2145d into rust-analyzer:master Apr 18, 2024
1 check passed
@alexheretic alexheretic deleted the replace branch April 18, 2024 12:18
@alexheretic
Copy link
Contributor Author

It would be nice to have a new release with this

@Veykril
Copy link
Member

Veykril commented May 14, 2024

Sorry, published 0.2.2 now

@Veykril
Copy link
Member

Veykril commented May 14, 2024

Or not, need to ask someone regarding perms as the team that managed them (which i was part of) has been deleted

@alexheretic
Copy link
Contributor Author

I guess you need to replace your ci CRATES_IO_TOKEN env var. You are a owner on crates.io so could also publish manually if you can't access to the repo settings.

@Veykril
Copy link
Member

Veykril commented May 14, 2024

I wasn't an owner a couple of minutes ago, just sorted it out publish succeeded now

@alexheretic
Copy link
Contributor Author

Wonderful cheers mate!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants