about summary refs log tree commit diff
path: root/src/test/codegen/src-hash-algorithm/src-hash-algorithm-md5.rs
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2020-09-19 11:47:39 +0200
committerGitHub <noreply@github.com>2020-09-19 11:47:39 +0200
commitbac2f393504309e505a08c0e66a0e8d66467cf32 (patch)
treee891b6d9314dd79c42bcf9bb8df92830756ad239 /src/test/codegen/src-hash-algorithm/src-hash-algorithm-md5.rs
parent3ebba83a47ab60cc478e8085be670c5c52d55cb7 (diff)
parent3d89ee9586354e736cfe4a472d8aaa507d10f77c (diff)
downloadrust-bac2f393504309e505a08c0e66a0e8d66467cf32.tar.gz
rust-bac2f393504309e505a08c0e66a0e8d66467cf32.zip
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
Diffstat (limited to 'src/test/codegen/src-hash-algorithm/src-hash-algorithm-md5.rs')
0 files changed, 0 insertions, 0 deletions