Skip to content

Commit 404a67e

Browse files
authored
hybrid-array: use From for Array<->[T; N] reference conversions (#1026)
...instead of `AsRef`/`AsMut`, which allows inference to work for those traits. Notably `[T; N]` doesn't impl `AsRef`/`AsMut` for itself, only for slices, so this is more consistent.
1 parent b45f35f commit 404a67e

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

hybrid-array/src/lib.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -212,17 +212,6 @@ where
212212
}
213213
}
214214

215-
impl<T, U, const N: usize> AsRef<[T; N]> for Array<T, U>
216-
where
217-
Self: ArrayOps<T, N>,
218-
U: ArraySize,
219-
{
220-
#[inline]
221-
fn as_ref(&self) -> &[T; N] {
222-
self.as_core_array()
223-
}
224-
}
225-
226215
impl<T, U> AsMut<[T]> for Array<T, U>
227216
where
228217
U: ArraySize,
@@ -233,17 +222,6 @@ where
233222
}
234223
}
235224

236-
impl<T, U, const N: usize> AsMut<[T; N]> for Array<T, U>
237-
where
238-
Self: ArrayOps<T, N>,
239-
U: ArraySize,
240-
{
241-
#[inline]
242-
fn as_mut(&mut self) -> &mut [T; N] {
243-
self.as_mut_core_array()
244-
}
245-
}
246-
247225
impl<T, U> Borrow<[T]> for Array<T, U>
248226
where
249227
U: ArraySize,
@@ -386,6 +364,17 @@ where
386364
}
387365
}
388366

367+
impl<'a, T, U, const N: usize> From<&'a Array<T, U>> for &'a [T; N]
368+
where
369+
Array<T, U>: ArrayOps<T, N>,
370+
U: ArraySize,
371+
{
372+
#[inline]
373+
fn from(array_ref: &'a Array<T, U>) -> &'a [T; N] {
374+
array_ref.as_core_array()
375+
}
376+
}
377+
389378
impl<'a, T, U, const N: usize> From<&'a mut [T; N]> for &'a mut Array<T, U>
390379
where
391380
Array<T, U>: ArrayOps<T, N>,
@@ -397,6 +386,17 @@ where
397386
}
398387
}
399388

389+
impl<'a, T, U, const N: usize> From<&'a mut Array<T, U>> for &'a mut [T; N]
390+
where
391+
Array<T, U>: ArrayOps<T, N>,
392+
U: ArraySize,
393+
{
394+
#[inline]
395+
fn from(array_ref: &'a mut Array<T, U>) -> &'a mut [T; N] {
396+
array_ref.as_mut_core_array()
397+
}
398+
}
399+
400400
impl<T, U> Hash for Array<T, U>
401401
where
402402
T: Hash,

0 commit comments

Comments
 (0)