mirror of
https://github.com/rust-embedded/heapless.git
synced 2025-09-28 21:10:28 +00:00
Merge pull request #255 from robinkrahl/vec-try-from
Implement TryFrom<&[T]> for Vec<T, N>
This commit is contained in:
commit
e3c536b3c2
13
src/vec.rs
13
src/vec.rs
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user