Merge pull request #255 from robinkrahl/vec-try-from

Implement TryFrom<&[T]> for Vec<T, N>
This commit is contained in:
Emil Fresk 2021-11-24 16:11:29 +01:00 committed by GitHub
commit e3c536b3c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,7 @@
use core::{cmp::Ordering, fmt, hash, iter::FromIterator, mem::MaybeUninit, ops, ptr, slice};
use core::{
cmp::Ordering, convert::TryFrom, fmt, hash, iter::FromIterator, mem::MaybeUninit, ops, ptr,
slice,
};
use hash32;
/// A fixed capacity [`Vec`](https://doc.rust-lang.org/std/vec/struct.Vec.html)
@ -569,6 +572,14 @@ impl<T, const N: usize> Drop for Vec<T, N> {
}
}
impl<'a, T: Clone, const N: usize> TryFrom<&'a [T]> for Vec<T, N> {
type Error = ();
fn try_from(slice: &'a [T]) -> Result<Self, Self::Error> {
Vec::from_slice(slice)
}
}
impl<T, const N: usize> Extend<T> for Vec<T, N> {
fn extend<I>(&mut self, iter: I)
where