diff --git a/Cargo.lock b/Cargo.lock index 68278b0..efc51bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,7 +30,7 @@ checksum = "b6b1fc10dbac614ebc03540c9dbd60e83887fda27794998c6528f1782047d540" [[package]] name = "hybrid-array" -version = "0.3.1" +version = "0.4.0-pre" dependencies = [ "bincode", "bytemuck", diff --git a/Cargo.toml b/Cargo.toml index c53f9bd..3c189c8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hybrid-array" -version = "0.3.1" +version = "0.4.0-pre" description = """ Hybrid typenum-based and const generic array types designed to provide the flexibility of typenum-based expressions while also allowing interoperability diff --git a/src/lib.rs b/src/lib.rs index eb4cf22..01888bc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -156,32 +156,6 @@ pub type ArrayN = Array::Size>; /// /// let arr: Array = Array([1, 2, 3]); /// ``` -/// -/// ## [`AsRef`] impls -/// -/// The [`AsRef`] trait can be used to convert from `&Array` to `&[T; N]` and vice versa: -/// -/// ``` -/// use hybrid_array::{Array, ArraySize, AssocArraySize, ArrayN, sizes::U3}; -/// -/// pub fn get_third_item_hybrid_array(arr_ref: &Array) -> &T { -/// &arr_ref[2] -/// } -/// -/// pub fn get_third_item_const_generic(arr_ref: &[T; N]) -> &T -/// where -/// [T; N]: AssocArraySize + AsRef> -/// { -/// get_third_item_hybrid_array(arr_ref.as_ref()) -/// } -/// -/// assert_eq!(get_third_item_const_generic(&[1u8, 2, 3, 4]), &3); -/// ``` -/// -/// Note that the [`AssocArraySize`] trait can be used to determine the appropriate -/// [`Array`] size for a given `[T; N]`, and the [`ArrayN`] trait (which internally uses -/// [`AssocArraySize`]) can be used to determine the specific [`Array`] type for a given -/// const generic size. #[repr(transparent)] pub struct Array(pub U::ArrayType); @@ -486,17 +460,6 @@ where } } -impl AsRef> for [T; N] -where - U: ArraySize = [T; N]>, -{ - #[inline] - fn as_ref(&self) -> &Array { - // SAFETY: `Self` is a `repr(transparent)` newtype for `[T; $len]` - unsafe { &*self.as_ptr().cast() } - } -} - impl AsMut<[T]> for Array where U: ArraySize, @@ -517,17 +480,6 @@ where } } -impl AsMut> for [T; N] -where - U: ArraySize = [T; N]>, -{ - #[inline] - fn as_mut(&mut self) -> &mut Array { - // SAFETY: `Self` is a `repr(transparent)` newtype for `[T; $len]` - unsafe { &mut *self.as_mut_ptr().cast() } - } -} - impl Borrow<[T]> for Array where U: ArraySize, @@ -663,7 +615,8 @@ where { #[inline] fn from(array_ref: &'a [T; N]) -> &'a Array { - array_ref.as_ref() + // SAFETY: `Self` is a `repr(transparent)` newtype for `[T; $len]` + unsafe { &*array_ref.as_ptr().cast() } } } @@ -683,7 +636,8 @@ where { #[inline] fn from(array_ref: &'a mut [T; N]) -> &'a mut Array { - array_ref.as_mut() + // SAFETY: `Self` is a `repr(transparent)` newtype for `[T; $len]` + unsafe { &mut *array_ref.as_mut_ptr().cast() } } }