From 5ba37a6b3ad376a24e9744cfaa1271d3d802c2c2 Mon Sep 17 00:00:00 2001 From: Evgeny Rozaliev Date: Tue, 17 Mar 2020 23:15:39 +0300 Subject: [PATCH] TinyVec::from([T]) (#66) --- src/tinyvec.rs | 6 ++++++ tests/tinyvec.rs | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/src/tinyvec.rs b/src/tinyvec.rs index 1dbfa48..90c197d 100644 --- a/src/tinyvec.rs +++ b/src/tinyvec.rs @@ -709,6 +709,12 @@ impl From> for TinyVec { } } +impl From for TinyVec { + fn from(array: A) -> Self { + TinyVec::Inline(ArrayVec::from(array)) + } +} + impl From<&'_ [T]> for TinyVec where T: Clone + Default, diff --git a/tests/tinyvec.rs b/tests/tinyvec.rs index 617193a..e02b647 100644 --- a/tests/tinyvec.rs +++ b/tests/tinyvec.rs @@ -84,3 +84,10 @@ fn TinyVec_from_slice_impl() { TinyVec::Inline(ArrayVec::from_array_len(same_size, 4)); assert_eq!(TinyVec::from(&same_size[..]), tinyvec); } + +#[test] +fn TinyVec_from_array() { + let array = [9, 8, 7, 6, 5, 4, 3, 2, 1]; + let tv = TinyVec::from(array); + assert_eq!(&array, &tv[..]); +}