-
Notifications
You must be signed in to change notification settings - Fork 13.3k
add #[experimental] as_string/as_vec functions #17447
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
Conversation
GitHub wouldn't let me reopen #16713. |
#[unsafe_destructor] | ||
impl<'a, T> Drop for AsVec<'a, T> { | ||
fn drop(&mut self) { | ||
self.x.len = 0; |
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.
A more forward-compatible way of doing this might be
mem::forget(mem::replace(self, Vec::new())).
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.
That would work but it won't necessary be optimized out. This will be forwards compatible because the basic properties of strings / vectors are going to end up as guarantees for unsafe
code. It's defined in the same module anyway.
First, sorry for the delay in decision about this PR, which was partly due to uncertainty around the overall strategy for improving We're now ready to move forward with this API. Although collections reform offers a somewhat more ergonomic and general way to improve Thanks for discovering and contributing this clever hack! |
A couple of questions:
|
That would be fine, although I think they're more tied to
It didn't feel right to associate them with
The type names could remain experimental even if the method is marked stable, since I doubt there are many cases where they need to be referred to. |
@thestinger Ok, thinking more about it, leaving these as free functions is probably for the best, but I do think they make sense to go in the slice modules, since the main "receiver" types are slice types. Also, what about r=me with the above. |
This provides a way to pass `&[T]` to functions taking `&U` where `U` is a `Vec<T>`. This is useful in many cases not covered by the Equiv trait or methods like `find_with` on TreeMap.
This provides a way to pass `&[T]` to functions taking `&U` where `U` is a `Vec<T>`. This is useful in many cases not covered by the Equiv trait or methods like `find_with` on TreeMap.
This provides a way to pass
&[T]
to functions taking&U
whereU
isa
Vec<T>
. This is useful in many cases not covered by the Equiv traitor methods like
find_with
on TreeMap.