Skip to content

Commit aac2639

Browse files
Implement Deref/DerefMut for array types
1 parent f7ab40d commit aac2639

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

library/core/src/array/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ use crate::mem::{self, MaybeUninit};
1414
use crate::ops::{
1515
ChangeOutputType, ControlFlow, FromResidual, Index, IndexMut, NeverShortCircuit, Residual, Try,
1616
};
17+
#[cfg(not(bootstrap))]
18+
use crate::ops::{Deref, DerefMut};
1719
use crate::slice::{Iter, IterMut};
1820

1921
mod equality;
@@ -301,6 +303,28 @@ where
301303
}
302304
}
303305

306+
#[stable(feature = "deref_on_arrays", since = "1.60.0")]
307+
#[rustc_const_unstable(feature = "const_deref_on_arrays", issue = "none")]
308+
#[cfg(not(bootstrap))]
309+
impl<T, const N: usize> const Deref for [T; N] {
310+
type Target = [T];
311+
312+
#[inline]
313+
fn deref(&self) -> &Self::Target {
314+
self as &[T]
315+
}
316+
}
317+
318+
#[stable(feature = "deref_on_arrays", since = "1.60.0")]
319+
#[rustc_const_unstable(feature = "const_deref_on_arrays", issue = "none")]
320+
#[cfg(not(bootstrap))]
321+
impl<T, const N: usize> const DerefMut for [T; N] {
322+
#[inline]
323+
fn deref_mut(&mut self) -> &mut Self::Target {
324+
self as &mut [T]
325+
}
326+
}
327+
304328
#[stable(feature = "rust1", since = "1.0.0")]
305329
impl<T: PartialOrd, const N: usize> PartialOrd for [T; N] {
306330
#[inline]

0 commit comments

Comments
 (0)