diff --git a/.github/workflows/hybrid-array.yml b/.github/workflows/hybrid-array.yml index 59844cd..ab907d1 100644 --- a/.github/workflows/hybrid-array.yml +++ b/.github/workflows/hybrid-array.yml @@ -37,6 +37,7 @@ jobs: toolchain: ${{ matrix.rust }} targets: ${{ matrix.target }} - run: cargo build --no-default-features --target ${{ matrix.target }} + - run: cargo build --no-default-features --target ${{ matrix.target }} --features alloc - run: cargo build --no-default-features --target ${{ matrix.target }} --features bytemuck - run: cargo build --no-default-features --target ${{ matrix.target }} --features extra-sizes - run: cargo build --no-default-features --target ${{ matrix.target }} --features serde @@ -110,6 +111,7 @@ jobs: with: toolchain: ${{ matrix.toolchain }} - run: cargo test + - run: cargo test --features alloc - run: cargo test --features bytemuck - run: cargo test --features extra-sizes - run: cargo test --features serde diff --git a/src/lib.rs b/src/lib.rs index 7b14093..d6bdd93 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -666,6 +666,52 @@ where } } +#[cfg(feature = "alloc")] +impl From> for alloc::boxed::Box<[T]> +where + U: ArraySize, +{ + #[inline] + fn from(array: Array) -> alloc::boxed::Box<[T]> { + array.into_iter().collect() + } +} + +#[cfg(feature = "alloc")] +impl From<&Array> for alloc::boxed::Box<[T]> +where + T: Clone, + U: ArraySize, +{ + #[inline] + fn from(array: &Array) -> alloc::boxed::Box<[T]> { + array.as_slice().into() + } +} + +#[cfg(feature = "alloc")] +impl From> for alloc::vec::Vec +where + U: ArraySize, +{ + #[inline] + fn from(array: Array) -> alloc::vec::Vec { + array.into_iter().collect() + } +} + +#[cfg(feature = "alloc")] +impl From<&Array> for alloc::vec::Vec +where + T: Clone, + U: ArraySize, +{ + #[inline] + fn from(array: &Array) -> alloc::vec::Vec { + array.as_slice().into() + } +} + impl Hash for Array where T: Hash,