Skip to content

Commit

Permalink
Overload get{,_mut}{,_unchecked}
Browse files Browse the repository at this point in the history
  • Loading branch information
sfackler committed Nov 26, 2016
1 parent a31ad75 commit 5377b5e
Show file tree
Hide file tree
Showing 7 changed files with 404 additions and 185 deletions.
1 change: 1 addition & 0 deletions src/libcollections/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#![feature(trusted_len)]
#![feature(unicode)]
#![feature(unique)]
#![feature(slice_get_slice)]
#![cfg_attr(test, feature(rand, test))]

#![no_std]
Expand Down
18 changes: 14 additions & 4 deletions src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ pub use core::slice::{SplitMut, ChunksMut, Split};
pub use core::slice::{SplitN, RSplitN, SplitNMut, RSplitNMut};
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::slice::{from_raw_parts, from_raw_parts_mut};
#[unstable(feature = "slice_get_slice", issue = "35729")]
pub use core::slice::SliceIndex;

////////////////////////////////////////////////////////////////////////////////
// Basic slice extension methods
Expand Down Expand Up @@ -353,7 +355,9 @@ impl<T> [T] {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn get(&self, index: usize) -> Option<&T> {
pub fn get<I>(&self, index: I) -> Option<&I::Output>
where I: SliceIndex<T>
{
core_slice::SliceExt::get(self, index)
}

Expand All @@ -372,7 +376,9 @@ impl<T> [T] {
/// or `None` if the index is out of bounds
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn get_mut(&mut self, index: usize) -> Option<&mut T> {
pub fn get_mut<I>(&mut self, index: I) -> Option<&mut I::Output>
where I: SliceIndex<T>
{
core_slice::SliceExt::get_mut(self, index)
}

Expand All @@ -390,7 +396,9 @@ impl<T> [T] {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub unsafe fn get_unchecked(&self, index: usize) -> &T {
pub unsafe fn get_unchecked<I>(&self, index: I) -> &I::Output
where I: SliceIndex<T>
{
core_slice::SliceExt::get_unchecked(self, index)
}

Expand All @@ -410,7 +418,9 @@ impl<T> [T] {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub unsafe fn get_unchecked_mut(&mut self, index: usize) -> &mut T {
pub unsafe fn get_unchecked_mut<I>(&mut self, index: I) -> &mut I::Output
where I: SliceIndex<T>
{
core_slice::SliceExt::get_unchecked_mut(self, index)
}

Expand Down
Loading

0 comments on commit 5377b5e

Please sign in to comment.