rust/library/alloc/src
Ralf Jung bac2f39350
Rollup merge of #76310 - scottmcm:array-try_from-vec, r=dtolnay
Add `[T; N]: TryFrom<Vec<T>>` (insta-stable)

This is very similar to the [existing](https://doc.rust-lang.org/nightly/std/convert/trait.TryFrom.html#impl-TryFrom%3CBox%3C%5BT%5D%3E%3E) `Box<[T; N]>: TryFrom<Box<[T]>>`, but allows avoiding the `shrink_to_fit` if you have a vector and not a boxed slice.

Like the slice equivalents of this, it fails if the length of the vector is not exactly `N`.
This uses `Vec<T>` as the `Error` type to return the input, like how the `Rc<[T]> -> Rc<[T; N]>` (and Arc) ones also reflect the input directly in the error type.

```rust
#[stable(feature = "array_try_from_vec", since = "1.47.0")]
impl<T, const N: usize> TryFrom<Vec<T>> for [T; N] {
    type Error = Vec<T>;
    fn try_from(mut vec: Vec<T>) -> Result<[T; N], Vec<T>>;
}
```

Inspired by this zulip thread: https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/APIs.20for.20getting.20stuff.20from.20a.20Vec.20by.20owned/near/209048103
2020-09-19 11:47:39 +02:00
..
alloc Replace Memoryblock with NonNull<[u8]> 2020-08-04 18:03:34 +02:00
collections Auto merge of #76790 - ssomers:btree_slice_slasher_returns, r=Mark-Simulacrum 2020-09-18 05:47:00 +00:00
prelude
raw_vec Replace Memoryblock with NonNull<[u8]> 2020-08-04 18:03:34 +02:00
rc impl Rc::new_cyclic 2020-08-27 19:19:29 +01:00
sync add missing newline 2020-08-14 01:28:04 +02:00
alloc.rs Capitalize safety comments 2020-09-08 22:37:18 -04:00
borrow.rs Make cow_is_borrowed methods const 2020-08-31 03:43:47 +02:00
boxed.rs Use intra-doc links for MaybeUninit in boxed.rs 2020-09-01 23:54:17 -04:00
fmt.rs Apply suggestions from code review 2020-08-21 19:31:00 +02:00
lib.rs Add array window fn 2020-09-16 14:52:20 +00:00
macros.rs Use intra-doc-links in alloc 2020-08-21 00:25:25 +02:00
raw_vec.rs Assume same alignment in RawVec 2020-08-20 11:56:46 +02:00
rc.rs Address review comments 2020-09-11 07:25:28 -05:00
slice.rs Rollup merge of #75026 - JulianKnodt:array_windows, r=Amanieu 2020-09-16 12:24:03 -07:00
str.rs
string.rs fix slice::check_range aliasing problems 2020-09-15 23:14:41 +02:00
sync.rs Revert change to MaybeUninit until rustdoc bugs are fixed 2020-09-02 17:38:21 -04:00
task.rs Allow unstable From impl for [Raw]Waker. 2020-09-11 13:36:45 +02:00
tests.rs
vec.rs Rollup merge of #76310 - scottmcm:array-try_from-vec, r=dtolnay 2020-09-19 11:47:39 +02:00