Skip to content

Commit 219f287

Browse files
Add as_mut_inner method (#215)
1 parent 5809985 commit 219f287

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

src/arrayvec.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,17 @@ impl<A> ArrayVec<A> {
12571257
pub const fn as_inner(&self) -> &A {
12581258
&self.data
12591259
}
1260+
1261+
/// Returns a mutable reference to the inner array of the `ArrayVec`.
1262+
///
1263+
/// This returns the full array, even if the `ArrayVec` length is currently
1264+
/// less than that.
1265+
#[inline(always)]
1266+
#[must_use]
1267+
#[cfg(feature = "latest_stable_rust")]
1268+
pub const fn as_mut_inner(&mut self) -> &mut A {
1269+
&mut self.data
1270+
}
12601271
}
12611272

12621273
/// Splicing iterator for `ArrayVec`

src/slicevec.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,29 @@ impl<'s, T> SliceVec<'s, T> {
634634
}
635635
}
636636

637+
impl<'s, T> SliceVec<'s, T> {
638+
/// Returns the reference to the inner slice of the `SliceVec`.
639+
///
640+
/// This returns the full array, even if the `SliceVec` length is currently
641+
/// less than that.
642+
#[inline(always)]
643+
#[must_use]
644+
pub const fn as_inner(&self) -> &[T] {
645+
&*self.data
646+
}
647+
648+
/// Returns a mutable reference to the inner slice of the `SliceVec`.
649+
///
650+
/// This returns the full array, even if the `SliceVec` length is currently
651+
/// less than that.
652+
#[inline(always)]
653+
#[must_use]
654+
#[cfg(feature = "latest_stable_rust")]
655+
pub const fn as_mut_inner(&mut self) -> &mut [T] {
656+
self.data
657+
}
658+
}
659+
637660
#[cfg(feature = "grab_spare_slice")]
638661
impl<'s, T> SliceVec<'s, T> {
639662
/// Obtain the shared slice of the array _after_ the active memory.

0 commit comments

Comments
 (0)