array_trait 1.1.20

A generic trait for any array, with item as type and length as const parameter
Documentation
use crate::AsArray;

#[cfg(not(feature = "alloc"))]
pub const trait IntoArray: ~const AsArray
{
    /// Returns self as an array
    /// 
    /// Useful in the case where a trait is implemented using a generic bound to the [Array](Array) trait.
    /// In this case, the compiler does not automatically know that the type with the [Array](Array)-trait is an actual array.
    /// This method lets you tell the compiler that you are now working with an actual array, and not just something
    /// which implements the trait [Array](Array).
    fn into_array(self) -> [Self::Elem; Self::LENGTH];
}

#[cfg(feature = "alloc")]
pub const trait IntoArray: ~const AsArray + slice_trait::IntoBoxedSlice
{
    /// Returns self as an array
    /// 
    /// Useful in the case where a trait is implemented using a generic bound to the [Array](Array) trait.
    /// In this case, the compiler does not automatically know that the type with the [Array](Array)-trait is an actual array.
    /// This method lets you tell the compiler that you are now working with an actual array, and not just something
    /// which implements the trait [Array](Array).
    fn into_array(self) -> [Self::Elem; Self::LENGTH];
}

impl<T, const LENGTH: usize> const IntoArray for [T; LENGTH]
{
    fn into_array(self) -> [Self::Elem; Self::LENGTH]
    {
        let array = unsafe {core::mem::transmute_copy(&self)};
        core::mem::forget(self);
        array
    }
}