-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add a method to convert a vector of Ascii
to a string slice without copying
#6120
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
The problem is that that's not generally possible without reqiring that the Ascii vector is one random byte longer than the slice you want. A str slice is one hidden byte longer than a vec slice. |
One way to solve this would be to turn ~[Ascii] into an own type AsciiStr, which holds the invariant that its always null terminated. Or we could just say that a [Ascii] may be optionally null terminated, that a trailing null is never considerd part of the string it represents, and that certain operations reqire it. |
I think #7599 enables this cleanly? |
@cmr I'm not sure how that Issue is related. |
@Kimundi err yeah, nevermind, sorry |
@erickt was experimenting with removing the null-terminator on |
Triage: null terminators are gone, so this will be fixed when #10333 lands. |
This renames to_str_ascii to as_str_ascii and makes it non-copying, which is possible now that strings no longer have a hidden extra byte/null terminator. Fixes #6120.
…arth Replace some lazy_static usage with once_cell feature This replaces some `lazy_static` usage with [`SyncLazy`](https://doc.rust-lang.org/nightly/std/lazy/struct.SyncLazy.html) of the unstable `once_cell` feature. changelog: none
As it says.
The text was updated successfully, but these errors were encountered: