@@ -171,41 +171,6 @@ pub type ArrayN<T, const N: usize> = Array<T, <[T; N] as AssocArraySize>::Size>;
171171///
172172/// let arr: Array<u8, U3> = Array([1, 2, 3]);
173173/// ```
174- ///
175- /// ## [`Borrow`] impls
176- ///
177- /// The [`Array`] type has impls of the [`Borrow`] trait from `core` for both `[T]` and `[T; N]`,
178- /// which should make it usable anywhere with e.g. `Borrow<[T]>` bounds.
179- ///
180- /// ### `Borrow<Array<T, U>>` for `[T; N]`
181- ///
182- /// This crate provides a `Borrow` impl for `[T; N]` which makes it possible to write APIs in terms
183- /// of `[T; N]` rather than `Array`, so the caller doesn't need to import `Array` at all:
184- ///
185- /// ```
186- /// use std::borrow::Borrow;
187- /// use hybrid_array::{Array, ArraySize, AssocArraySize, ArrayN, sizes::U3};
188- ///
189- /// pub fn getn_hybrid<T, U: ArraySize>(arr: &Array<T, U>, n: usize) -> &T {
190- /// &arr[2]
191- /// }
192- ///
193- /// pub fn getn_generic<T, const N: usize>(arr: &[T; N], n: usize) -> &T
194- /// where
195- /// [T; N]: AssocArraySize + Borrow<ArrayN<T, N>>
196- /// {
197- /// getn_hybrid(arr.borrow(), n)
198- /// }
199- ///
200- /// let array = [0u8, 1, 2, 3];
201- /// let x = getn_generic(&array, 2);
202- /// assert_eq!(x, &2);
203- /// ```
204- ///
205- /// Note that the [`AssocArraySize`] trait can be used to determine the appropriate
206- /// [`Array`] size for a given `[T; N]`, and the [`ArrayN`] trait (which internally uses
207- /// [`AssocArraySize`]) can be used to determine the specific [`Array`] type for a given
208- /// const generic size.
209174#[ repr( transparent) ]
210175pub struct Array < T , U : ArraySize > ( pub U :: ArrayType < T > ) ;
211176
@@ -540,16 +505,6 @@ where
540505 }
541506}
542507
543- impl < T , U > BorrowMut < [ T ] > for Array < T , U >
544- where
545- U : ArraySize ,
546- {
547- #[ inline]
548- fn borrow_mut ( & mut self ) -> & mut [ T ] {
549- self . 0 . as_mut ( )
550- }
551- }
552-
553508impl < T , U , const N : usize > Borrow < [ T ; N ] > for Array < T , U >
554509where
555510 U : ArraySize < ArrayType < T > = [ T ; N ] > ,
@@ -560,33 +515,23 @@ where
560515 }
561516}
562517
563- impl < T , U , const N : usize > BorrowMut < [ T ; N ] > for Array < T , U >
564- where
565- U : ArraySize < ArrayType < T > = [ T ; N ] > ,
566- {
567- #[ inline]
568- fn borrow_mut ( & mut self ) -> & mut [ T ; N ] {
569- & mut self . 0
570- }
571- }
572-
573- impl < T , U , const N : usize > Borrow < Array < T , U > > for [ T ; N ]
518+ impl < T , U > BorrowMut < [ T ] > for Array < T , U >
574519where
575- U : ArraySize < ArrayType < T > = [ T ; N ] > ,
520+ U : ArraySize ,
576521{
577522 #[ inline]
578- fn borrow ( & self ) -> & Array < T , U > {
579- self . into ( )
523+ fn borrow_mut ( & mut self ) -> & mut [ T ] {
524+ self . 0 . as_mut ( )
580525 }
581526}
582527
583- impl < T , U , const N : usize > BorrowMut < Array < T , U > > for [ T ; N ]
528+ impl < T , U , const N : usize > BorrowMut < [ T ; N ] > for Array < T , U >
584529where
585530 U : ArraySize < ArrayType < T > = [ T ; N ] > ,
586531{
587532 #[ inline]
588- fn borrow_mut ( & mut self ) -> & mut Array < T , U > {
589- self . into ( )
533+ fn borrow_mut ( & mut self ) -> & mut [ T ; N ] {
534+ & mut self . 0
590535 }
591536}
592537
0 commit comments