-
Notifications
You must be signed in to change notification settings - Fork 19
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
Implement From<{&,&mut} [T; N]>
for Vec<T>
where T: Clone
#220
Comments
The Imo it's worth checking if this can be improved on the language side, e.g. by inserting an anonymous shim function. I don't know if that would be acceptable since it would result in a different Fn type in the iterator adapter. |
We discussed this in the libs-api meeting today. We're happy to add this, but it might be worth doing a crater run to check for type inference failures. |
…-vec, r=dtolnay Implement `From<{&,&mut} [T; N]>` for `Vec<T>` where `T: Clone` Currently, if `T` implements `Clone`, we can create a `Vec<T>` from an `&[T]` or an `&mut [T]`, can we also support creating a `Vec<T>` from an `&[T; N]` or an `&mut [T; N]`? Also, do I need to add `#[inline]` to the implementation? ACP: rust-lang/libs-team#220. [Accepted] Closes rust-lang#100880.
…tolnay Implement `From<{&,&mut} [T; N]>` for `Vec<T>` where `T: Clone` Currently, if `T` implements `Clone`, we can create a `Vec<T>` from an `&[T]` or an `&mut [T]`, can we also support creating a `Vec<T>` from an `&[T; N]` or an `&mut [T; N]`? Also, do I need to add `#[inline]` to the implementation? ACP: rust-lang/libs-team#220. [Accepted] Closes #100880.
…tolnay Implement `From<{&,&mut} [T; N]>` for `Vec<T>` where `T: Clone` Currently, if `T` implements `Clone`, we can create a `Vec<T>` from an `&[T]` or an `&mut [T]`, can we also support creating a `Vec<T>` from an `&[T; N]` or an `&mut [T; N]`? Also, do I need to add `#[inline]` to the implementation? ACP: rust-lang/libs-team#220. [Accepted] Closes #100880.
…tolnay Implement `From<{&,&mut} [T; N]>` for `Vec<T>` where `T: Clone` Currently, if `T` implements `Clone`, we can create a `Vec<T>` from an `&[T]` or an `&mut [T]`, can we also support creating a `Vec<T>` from an `&[T; N]` or an `&mut [T; N]`? Also, do I need to add `#[inline]` to the implementation? ACP: rust-lang/libs-team#220. [Accepted] Closes #100880.
Proposal
Problem statement
Currently, we have
From<{&,&mut} [T]>
forVec<T>
whereT: Clone
, I think we can also implementFrom<{&,&mut} [T; N]>
forVec<T>
whereT: Clone
.Motivation, use-cases
Suppose I want to convert an
&[[u32; 4]]
value to aVec<Vec<u32>>
type. Currently, I can write:items.iter().map(|item| item.to_vec()).collect::<Vec<_>>()
;items.iter().copied().map(Vec::from).collect::<Vec<_>>()
;I want to be able to write:
items.iter().map(Vec::from).collect::<Vec<_>>()
;Solution sketches
Implement
From<{&,&mut} [T; N]>
forVec<T>
whereT: Clone
.Links and related work
From<&[T]>
.From<&mut [T]>
.From<{&,&mut} [T; N]>
forVec<T>
whereT: Clone
rust#111278.What happens now?
This issue is part of the libs-api team API change proposal process. Once this issue is filed the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.
The text was updated successfully, but these errors were encountered: