Skip to content

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

Closed
pcwalton opened this issue Apr 30, 2013 · 7 comments · Fixed by #10333
Closed

Add a method to convert a vector of Ascii to a string slice without copying #6120

pcwalton opened this issue Apr 30, 2013 · 7 comments · Fixed by #10333
Labels
I-slow Issue: Problems and improvements with respect to performance of generated code.

Comments

@pcwalton
Copy link
Contributor

As it says.

@Kimundi
Copy link
Member

Kimundi commented Apr 30, 2013

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.

@Kimundi
Copy link
Member

Kimundi commented Apr 30, 2013

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.

@emberian
Copy link
Member

I think #7599 enables this cleanly?

@Kimundi
Copy link
Member

Kimundi commented Jul 12, 2013

@cmr I'm not sure how that Issue is related.

@emberian
Copy link
Member

@Kimundi err yeah, nevermind, sorry

@huonw
Copy link
Member

huonw commented Jul 13, 2013

@erickt was experimenting with removing the null-terminator on ~strs, which would make this possible. (Preferably by implementing the std::str::Str trait.)

@huonw
Copy link
Member

huonw commented Nov 7, 2013

Triage: null terminators are gone, so this will be fixed when #10333 lands.

bors added a commit that referenced this issue Nov 8, 2013
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.
@huonw huonw closed this as completed in b95a8c6 Nov 8, 2013
flip1995 pushed a commit to flip1995/rust that referenced this issue Oct 9, 2020
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-slow Issue: Problems and improvements with respect to performance of generated code.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants