auto merge of #18698 : japaric/rust/index, r=alexcrichton
Closes #16529 r? @aturon
This commit is contained in:
commit
932eec7d70
2 changed files with 18 additions and 3 deletions
|
@ -638,7 +638,7 @@ shr_impl!(uint u8 u16 u32 u64 int i8 i16 i32 i64)
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
#[lang="index"]
|
#[lang="index"]
|
||||||
pub trait Index<Index, Sized? Result> {
|
pub trait Index<Index, Sized? Result> for Sized? {
|
||||||
/// The method for the indexing (`Foo[Bar]`) operation
|
/// The method for the indexing (`Foo[Bar]`) operation
|
||||||
fn index<'a>(&'a self, index: &Index) -> &'a Result;
|
fn index<'a>(&'a self, index: &Index) -> &'a Result;
|
||||||
}
|
}
|
||||||
|
@ -669,7 +669,7 @@ pub trait Index<Index, Sized? Result> {
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
#[lang="index_mut"]
|
#[lang="index_mut"]
|
||||||
pub trait IndexMut<Index, Result> {
|
pub trait IndexMut<Index, Result> for Sized? {
|
||||||
/// The method for the indexing (`Foo[Bar]`) operation
|
/// The method for the indexing (`Foo[Bar]`) operation
|
||||||
fn index_mut<'a>(&'a mut self, index: &Index) -> &'a mut Result;
|
fn index_mut<'a>(&'a mut self, index: &Index) -> &'a mut Result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -256,7 +256,6 @@ pub trait SlicePrelude<T> for Sized? {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[experimental = "not triaged yet"]
|
#[experimental = "not triaged yet"]
|
||||||
fn is_empty(&self) -> bool { self.len() == 0 }
|
fn is_empty(&self) -> bool { self.len() == 0 }
|
||||||
|
|
||||||
/// Returns a mutable reference to the element at the given index,
|
/// Returns a mutable reference to the element at the given index,
|
||||||
/// or `None` if the index is out of bounds
|
/// or `None` if the index is out of bounds
|
||||||
#[unstable = "waiting on final error conventions"]
|
#[unstable = "waiting on final error conventions"]
|
||||||
|
@ -698,6 +697,22 @@ impl<T> SlicePrelude<T> for [T] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T> ops::Index<uint, T> for [T] {
|
||||||
|
fn index(&self, &index: &uint) -> &T {
|
||||||
|
assert!(index < self.len());
|
||||||
|
|
||||||
|
unsafe { mem::transmute(self.repr().data.offset(index as int)) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> ops::IndexMut<uint, T> for [T] {
|
||||||
|
fn index_mut(&mut self, &index: &uint) -> &mut T {
|
||||||
|
assert!(index < self.len());
|
||||||
|
|
||||||
|
unsafe { mem::transmute(self.repr().data.offset(index as int)) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T> ops::Slice<uint, [T]> for [T] {
|
impl<T> ops::Slice<uint, [T]> for [T] {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn as_slice_<'a>(&'a self) -> &'a [T] {
|
fn as_slice_<'a>(&'a self) -> &'a [T] {
|
||||||
|
|
Loading…
Reference in a new issue