-
Notifications
You must be signed in to change notification settings - Fork 28
Add Encoding::encode_mut_str
#136
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
Comments
No I don't consider this a micro-optimization. This is a very legitimate request and something I was even considering for |
That was fast! |
This got released in #138, see |
Thanks for the update. Tangentially related, before If so, what stops you from publishing a
I do find ^that interesting. It appears |
Not exactly, because of how Cargo pre-releases work. Instead I'll follow something along the lines of rust-lang/cargo#2222 (comment): use
I don't think I'll publish pre-releases on
I'm not satisfied with the current code, but I've still published Regarding the |
Would it be possible to add a method like
Encoding::encode_mut
except have it return&str
instead of()
? The purpose of such a method would be to allow for downstream code to use stack-allocated strings without having to useunsafe
code or callcore::str::from_utf8
and incur unnecessary overhead of UTF-8 validation.Essentially the method would look similar to below with possible changes to call
str::from_utf8_unchecked
on a sub-slice ofoutput
in the event it's not guaranteed the entirety ofoutput
would be written to:Currently downstream code is forced to do either
or
With
encode_mut_str
, then the above could be written like:When
unsafe
code is used, it's a lot better for the code to be entirely localized and not have to rely on an external crate to uphold the safety invariants. I realize this can be considered micro-optimization, but I thought I'd ask.The text was updated successfully, but these errors were encountered: