mirror of
https://github.com/rust-embedded/heapless.git
synced 2025-10-02 06:50:32 +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;
|
use hash32;
|
||||||
|
|
||||||
/// A fixed capacity [`Vec`](https://doc.rust-lang.org/std/vec/struct.Vec.html)
|
/// 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> {
|
impl<T, const N: usize> Extend<T> for Vec<T, N> {
|
||||||
fn extend<I>(&mut self, iter: I)
|
fn extend<I>(&mut self, iter: I)
|
||||||
where
|
where
|
||||||
|
Loading…
x
Reference in New Issue
Block a user