Adjust Index/IndexMut impls. For generic collections, we take
references. For collections whose keys are integers, we take both references and by-value.
This commit is contained in:
parent
bc1dde468c
commit
b4d4daf007
|
@ -914,12 +914,27 @@ impl<K: Debug, V: Debug> Debug for BTreeMap<K, V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<K: Ord, Q: ?Sized, V> Index<Q> for BTreeMap<K, V>
|
impl<K: Ord, Q: ?Sized, V> Index<Q> for BTreeMap<K, V>
|
||||||
where K: Borrow<Q>, Q: Ord
|
where K: Borrow<Q>, Q: Ord
|
||||||
{
|
{
|
||||||
type Output = V;
|
type Output = V;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, key: &Q) -> &V {
|
||||||
|
self.get(key).expect("no entry found for key")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
impl<'a, K: Ord, Q: ?Sized, V> Index<&'a Q> for BTreeMap<K, V>
|
||||||
|
where K: Borrow<Q>, Q: Ord
|
||||||
|
{
|
||||||
|
type Output = V;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn index(&self, key: &Q) -> &V {
|
fn index(&self, key: &Q) -> &V {
|
||||||
self.get(key).expect("no entry found for key")
|
self.get(key).expect("no entry found for key")
|
||||||
}
|
}
|
||||||
|
|
|
@ -870,34 +870,66 @@ impl<'a> Add<&'a str> for String {
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl ops::Index<ops::Range<usize>> for String {
|
impl ops::Index<ops::Range<usize>> for String {
|
||||||
type Output = str;
|
type Output = str;
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, index: &ops::Range<usize>) -> &str {
|
fn index(&self, index: &ops::Range<usize>) -> &str {
|
||||||
&self[..][*index]
|
&self[..][*index]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, index: ops::Range<usize>) -> &str {
|
||||||
|
&self[..][index]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl ops::Index<ops::RangeTo<usize>> for String {
|
impl ops::Index<ops::RangeTo<usize>> for String {
|
||||||
type Output = str;
|
type Output = str;
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, index: &ops::RangeTo<usize>) -> &str {
|
fn index(&self, index: &ops::RangeTo<usize>) -> &str {
|
||||||
&self[..][*index]
|
&self[..][*index]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, index: ops::RangeTo<usize>) -> &str {
|
||||||
|
&self[..][index]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl ops::Index<ops::RangeFrom<usize>> for String {
|
impl ops::Index<ops::RangeFrom<usize>> for String {
|
||||||
type Output = str;
|
type Output = str;
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, index: &ops::RangeFrom<usize>) -> &str {
|
fn index(&self, index: &ops::RangeFrom<usize>) -> &str {
|
||||||
&self[..][*index]
|
&self[..][*index]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, index: ops::RangeFrom<usize>) -> &str {
|
||||||
|
&self[..][index]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl ops::Index<ops::RangeFull> for String {
|
impl ops::Index<ops::RangeFull> for String {
|
||||||
type Output = str;
|
type Output = str;
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, _index: &ops::RangeFull) -> &str {
|
fn index(&self, _index: &ops::RangeFull) -> &str {
|
||||||
unsafe { mem::transmute(&*self.vec) }
|
unsafe { mem::transmute(&*self.vec) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, _index: ops::RangeFull) -> &str {
|
||||||
|
unsafe { mem::transmute(&*self.vec) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
|
|
@ -1323,83 +1323,165 @@ impl<T: Hash> Hash for Vec<T> {
|
||||||
impl<T> Index<usize> for Vec<T> {
|
impl<T> Index<usize> for Vec<T> {
|
||||||
type Output = T;
|
type Output = T;
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, index: &usize) -> &T {
|
fn index(&self, index: &usize) -> &T {
|
||||||
// NB built-in indexing via `&[T]`
|
// NB built-in indexing via `&[T]`
|
||||||
&(**self)[*index]
|
&(**self)[*index]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, index: usize) -> &T {
|
||||||
|
// NB built-in indexing via `&[T]`
|
||||||
|
&(**self)[index]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<T> IndexMut<usize> for Vec<T> {
|
impl<T> IndexMut<usize> for Vec<T> {
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index_mut(&mut self, index: &usize) -> &mut T {
|
fn index_mut(&mut self, index: &usize) -> &mut T {
|
||||||
// NB built-in indexing via `&mut [T]`
|
// NB built-in indexing via `&mut [T]`
|
||||||
&mut (**self)[*index]
|
&mut (**self)[*index]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index_mut(&mut self, index: usize) -> &mut T {
|
||||||
|
// NB built-in indexing via `&mut [T]`
|
||||||
|
&mut (**self)[index]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<T> ops::Index<ops::Range<usize>> for Vec<T> {
|
impl<T> ops::Index<ops::Range<usize>> for Vec<T> {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, index: &ops::Range<usize>) -> &[T] {
|
fn index(&self, index: &ops::Range<usize>) -> &[T] {
|
||||||
Index::index(&**self, index)
|
Index::index(&**self, index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, index: ops::Range<usize>) -> &[T] {
|
||||||
|
Index::index(&**self, index)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<T> ops::Index<ops::RangeTo<usize>> for Vec<T> {
|
impl<T> ops::Index<ops::RangeTo<usize>> for Vec<T> {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, index: &ops::RangeTo<usize>) -> &[T] {
|
fn index(&self, index: &ops::RangeTo<usize>) -> &[T] {
|
||||||
Index::index(&**self, index)
|
Index::index(&**self, index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, index: ops::RangeTo<usize>) -> &[T] {
|
||||||
|
Index::index(&**self, index)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<T> ops::Index<ops::RangeFrom<usize>> for Vec<T> {
|
impl<T> ops::Index<ops::RangeFrom<usize>> for Vec<T> {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, index: &ops::RangeFrom<usize>) -> &[T] {
|
fn index(&self, index: &ops::RangeFrom<usize>) -> &[T] {
|
||||||
Index::index(&**self, index)
|
Index::index(&**self, index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, index: ops::RangeFrom<usize>) -> &[T] {
|
||||||
|
Index::index(&**self, index)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<T> ops::Index<ops::RangeFull> for Vec<T> {
|
impl<T> ops::Index<ops::RangeFull> for Vec<T> {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, _index: &ops::RangeFull) -> &[T] {
|
fn index(&self, _index: &ops::RangeFull) -> &[T] {
|
||||||
self.as_slice()
|
self.as_slice()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, _index: ops::RangeFull) -> &[T] {
|
||||||
|
self.as_slice()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<T> ops::IndexMut<ops::Range<usize>> for Vec<T> {
|
impl<T> ops::IndexMut<ops::Range<usize>> for Vec<T> {
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index_mut(&mut self, index: &ops::Range<usize>) -> &mut [T] {
|
fn index_mut(&mut self, index: &ops::Range<usize>) -> &mut [T] {
|
||||||
IndexMut::index_mut(&mut **self, index)
|
IndexMut::index_mut(&mut **self, index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index_mut(&mut self, index: ops::Range<usize>) -> &mut [T] {
|
||||||
|
IndexMut::index_mut(&mut **self, index)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<T> ops::IndexMut<ops::RangeTo<usize>> for Vec<T> {
|
impl<T> ops::IndexMut<ops::RangeTo<usize>> for Vec<T> {
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index_mut(&mut self, index: &ops::RangeTo<usize>) -> &mut [T] {
|
fn index_mut(&mut self, index: &ops::RangeTo<usize>) -> &mut [T] {
|
||||||
IndexMut::index_mut(&mut **self, index)
|
IndexMut::index_mut(&mut **self, index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index_mut(&mut self, index: ops::RangeTo<usize>) -> &mut [T] {
|
||||||
|
IndexMut::index_mut(&mut **self, index)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<T> ops::IndexMut<ops::RangeFrom<usize>> for Vec<T> {
|
impl<T> ops::IndexMut<ops::RangeFrom<usize>> for Vec<T> {
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index_mut(&mut self, index: &ops::RangeFrom<usize>) -> &mut [T] {
|
fn index_mut(&mut self, index: &ops::RangeFrom<usize>) -> &mut [T] {
|
||||||
IndexMut::index_mut(&mut **self, index)
|
IndexMut::index_mut(&mut **self, index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index_mut(&mut self, index: ops::RangeFrom<usize>) -> &mut [T] {
|
||||||
|
IndexMut::index_mut(&mut **self, index)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<T> ops::IndexMut<ops::RangeFull> for Vec<T> {
|
impl<T> ops::IndexMut<ops::RangeFull> for Vec<T> {
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index_mut(&mut self, _index: &ops::RangeFull) -> &mut [T] {
|
fn index_mut(&mut self, _index: &ops::RangeFull) -> &mut [T] {
|
||||||
self.as_mut_slice()
|
self.as_mut_slice()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index_mut(&mut self, _index: ops::RangeFull) -> &mut [T] {
|
||||||
|
self.as_mut_slice()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
|
|
@ -1689,18 +1689,32 @@ impl<A: Hash> Hash for VecDeque<A> {
|
||||||
impl<A> Index<usize> for VecDeque<A> {
|
impl<A> Index<usize> for VecDeque<A> {
|
||||||
type Output = A;
|
type Output = A;
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, i: &usize) -> &A {
|
fn index(&self, i: &usize) -> &A {
|
||||||
self.get(*i).expect("Out of bounds access")
|
self.get(*i).expect("Out of bounds access")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, i: usize) -> &A {
|
||||||
|
self.get(i).expect("Out of bounds access")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<A> IndexMut<usize> for VecDeque<A> {
|
impl<A> IndexMut<usize> for VecDeque<A> {
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index_mut(&mut self, i: &usize) -> &mut A {
|
fn index_mut(&mut self, i: &usize) -> &mut A {
|
||||||
self.get_mut(*i).expect("Out of bounds access")
|
self.get_mut(*i).expect("Out of bounds access")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index_mut(&mut self, i: usize) -> &mut A {
|
||||||
|
self.get_mut(i).expect("Out of bounds access")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
|
|
@ -798,6 +798,7 @@ impl<V> Extend<(usize, V)> for VecMap<V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
impl<V> Index<usize> for VecMap<V> {
|
impl<V> Index<usize> for VecMap<V> {
|
||||||
type Output = V;
|
type Output = V;
|
||||||
|
|
||||||
|
@ -807,10 +808,49 @@ impl<V> Index<usize> for VecMap<V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
impl<V> Index<usize> for VecMap<V> {
|
||||||
|
type Output = V;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn index<'a>(&'a self, i: usize) -> &'a V {
|
||||||
|
self.get(&i).expect("key not present")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
impl<'a,V> Index<&'a usize> for VecMap<V> {
|
||||||
|
type Output = V;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, i: &usize) -> &V {
|
||||||
|
self.get(i).expect("key not present")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<V> IndexMut<usize> for VecMap<V> {
|
impl<V> IndexMut<usize> for VecMap<V> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index_mut<'a>(&'a mut self, i: &usize) -> &'a mut V {
|
fn index_mut(&mut self, i: &usize) -> &mut V {
|
||||||
|
self.get_mut(&i).expect("key not present")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
impl<V> IndexMut<usize> for VecMap<V> {
|
||||||
|
#[inline]
|
||||||
|
fn index_mut(&mut self, i: usize) -> &mut V {
|
||||||
|
self.get_mut(&i).expect("key not present")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
impl<'a, V> IndexMut<&'a usize> for VecMap<V> {
|
||||||
|
#[inline]
|
||||||
|
fn index_mut(&mut self, i: &usize) -> &mut V {
|
||||||
self.get_mut(i).expect("key not present")
|
self.get_mut(i).expect("key not present")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -898,7 +898,7 @@ shr_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize }
|
||||||
/// impl Index<Bar> for Foo {
|
/// impl Index<Bar> for Foo {
|
||||||
/// type Output = Foo;
|
/// type Output = Foo;
|
||||||
///
|
///
|
||||||
/// fn index<'a>(&'a self, _index: &Bar) -> &'a Foo {
|
/// fn index<'a>(&'a self, _index: Bar) -> &'a Foo {
|
||||||
/// println!("Indexing!");
|
/// println!("Indexing!");
|
||||||
/// self
|
/// self
|
||||||
/// }
|
/// }
|
||||||
|
@ -945,13 +945,13 @@ pub trait Index<Idx: ?Sized> {
|
||||||
/// impl Index<Bar> for Foo {
|
/// impl Index<Bar> for Foo {
|
||||||
/// type Output = Foo;
|
/// type Output = Foo;
|
||||||
///
|
///
|
||||||
/// fn index<'a>(&'a self, _index: &Bar) -> &'a Foo {
|
/// fn index<'a>(&'a self, _index: Bar) -> &'a Foo {
|
||||||
/// self
|
/// self
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// impl IndexMut<Bar> for Foo {
|
/// impl IndexMut<Bar> for Foo {
|
||||||
/// fn index_mut<'a>(&'a mut self, _index: &Bar) -> &'a mut Foo {
|
/// fn index_mut<'a>(&'a mut self, _index: Bar) -> &'a mut Foo {
|
||||||
/// println!("Indexing!");
|
/// println!("Indexing!");
|
||||||
/// self
|
/// self
|
||||||
/// }
|
/// }
|
||||||
|
|
|
@ -263,6 +263,7 @@ impl<T> SliceExt for [T] {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn as_mut_slice(&mut self) -> &mut [T] { self }
|
fn as_mut_slice(&mut self) -> &mut [T] { self }
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn split_at_mut(&mut self, mid: usize) -> (&mut [T], &mut [T]) {
|
fn split_at_mut(&mut self, mid: usize) -> (&mut [T], &mut [T]) {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -273,6 +274,17 @@ impl<T> SliceExt for [T] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn split_at_mut(&mut self, mid: usize) -> (&mut [T], &mut [T]) {
|
||||||
|
unsafe {
|
||||||
|
let self2: &mut [T] = mem::transmute_copy(&self);
|
||||||
|
|
||||||
|
(ops::IndexMut::index_mut(self, ops::RangeTo { end: mid } ),
|
||||||
|
ops::IndexMut::index_mut(self2, ops::RangeFrom { start: mid } ))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn iter_mut<'a>(&'a mut self) -> IterMut<'a, T> {
|
fn iter_mut<'a>(&'a mut self) -> IterMut<'a, T> {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -495,25 +507,45 @@ impl<T> SliceExt for [T] {
|
||||||
impl<T> ops::Index<usize> for [T] {
|
impl<T> ops::Index<usize> for [T] {
|
||||||
type Output = T;
|
type Output = T;
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
fn index(&self, &index: &usize) -> &T {
|
fn index(&self, &index: &usize) -> &T {
|
||||||
assert!(index < self.len());
|
assert!(index < self.len());
|
||||||
|
|
||||||
unsafe { mem::transmute(self.repr().data.offset(index as isize)) }
|
unsafe { mem::transmute(self.repr().data.offset(index as isize)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
fn index(&self, index: usize) -> &T {
|
||||||
|
assert!(index < self.len());
|
||||||
|
|
||||||
|
unsafe { mem::transmute(self.repr().data.offset(index as isize)) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<T> ops::IndexMut<usize> for [T] {
|
impl<T> ops::IndexMut<usize> for [T] {
|
||||||
|
#[cfg(stage0)]
|
||||||
|
#[inline]
|
||||||
fn index_mut(&mut self, &index: &usize) -> &mut T {
|
fn index_mut(&mut self, &index: &usize) -> &mut T {
|
||||||
assert!(index < self.len());
|
assert!(index < self.len());
|
||||||
|
|
||||||
unsafe { mem::transmute(self.repr().data.offset(index as isize)) }
|
unsafe { mem::transmute(self.repr().data.offset(index as isize)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index_mut(&mut self, index: usize) -> &mut T {
|
||||||
|
assert!(index < self.len());
|
||||||
|
|
||||||
|
unsafe { mem::transmute(self.repr().data.offset(index as isize)) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<T> ops::Index<ops::Range<usize>> for [T] {
|
impl<T> ops::Index<ops::Range<usize>> for [T] {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, index: &ops::Range<usize>) -> &[T] {
|
fn index(&self, index: &ops::Range<usize>) -> &[T] {
|
||||||
assert!(index.start <= index.end);
|
assert!(index.start <= index.end);
|
||||||
|
@ -525,34 +557,72 @@ impl<T> ops::Index<ops::Range<usize>> for [T] {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, index: ops::Range<usize>) -> &[T] {
|
||||||
|
assert!(index.start <= index.end);
|
||||||
|
assert!(index.end <= self.len());
|
||||||
|
unsafe {
|
||||||
|
from_raw_parts (
|
||||||
|
self.as_ptr().offset(index.start as isize),
|
||||||
|
index.end - index.start
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<T> ops::Index<ops::RangeTo<usize>> for [T] {
|
impl<T> ops::Index<ops::RangeTo<usize>> for [T] {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, index: &ops::RangeTo<usize>) -> &[T] {
|
fn index(&self, index: &ops::RangeTo<usize>) -> &[T] {
|
||||||
self.index(&ops::Range{ start: 0, end: index.end })
|
self.index(&ops::Range{ start: 0, end: index.end })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, index: ops::RangeTo<usize>) -> &[T] {
|
||||||
|
self.index(ops::Range{ start: 0, end: index.end })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<T> ops::Index<ops::RangeFrom<usize>> for [T] {
|
impl<T> ops::Index<ops::RangeFrom<usize>> for [T] {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, index: &ops::RangeFrom<usize>) -> &[T] {
|
fn index(&self, index: &ops::RangeFrom<usize>) -> &[T] {
|
||||||
self.index(&ops::Range{ start: index.start, end: self.len() })
|
self.index(&ops::Range{ start: index.start, end: self.len() })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, index: ops::RangeFrom<usize>) -> &[T] {
|
||||||
|
self.index(ops::Range{ start: index.start, end: self.len() })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<T> ops::Index<RangeFull> for [T] {
|
impl<T> ops::Index<RangeFull> for [T] {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, _index: &RangeFull) -> &[T] {
|
fn index(&self, _index: &RangeFull) -> &[T] {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, _index: RangeFull) -> &[T] {
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<T> ops::IndexMut<ops::Range<usize>> for [T] {
|
impl<T> ops::IndexMut<ops::Range<usize>> for [T] {
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index_mut(&mut self, index: &ops::Range<usize>) -> &mut [T] {
|
fn index_mut(&mut self, index: &ops::Range<usize>) -> &mut [T] {
|
||||||
assert!(index.start <= index.end);
|
assert!(index.start <= index.end);
|
||||||
|
@ -564,28 +634,64 @@ impl<T> ops::IndexMut<ops::Range<usize>> for [T] {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index_mut(&mut self, index: ops::Range<usize>) -> &mut [T] {
|
||||||
|
assert!(index.start <= index.end);
|
||||||
|
assert!(index.end <= self.len());
|
||||||
|
unsafe {
|
||||||
|
from_raw_parts_mut(
|
||||||
|
self.as_mut_ptr().offset(index.start as isize),
|
||||||
|
index.end - index.start
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<T> ops::IndexMut<ops::RangeTo<usize>> for [T] {
|
impl<T> ops::IndexMut<ops::RangeTo<usize>> for [T] {
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index_mut(&mut self, index: &ops::RangeTo<usize>) -> &mut [T] {
|
fn index_mut(&mut self, index: &ops::RangeTo<usize>) -> &mut [T] {
|
||||||
self.index_mut(&ops::Range{ start: 0, end: index.end })
|
self.index_mut(&ops::Range{ start: 0, end: index.end })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index_mut(&mut self, index: ops::RangeTo<usize>) -> &mut [T] {
|
||||||
|
self.index_mut(ops::Range{ start: 0, end: index.end })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<T> ops::IndexMut<ops::RangeFrom<usize>> for [T] {
|
impl<T> ops::IndexMut<ops::RangeFrom<usize>> for [T] {
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index_mut(&mut self, index: &ops::RangeFrom<usize>) -> &mut [T] {
|
fn index_mut(&mut self, index: &ops::RangeFrom<usize>) -> &mut [T] {
|
||||||
let len = self.len();
|
let len = self.len();
|
||||||
self.index_mut(&ops::Range{ start: index.start, end: len })
|
self.index_mut(&ops::Range{ start: index.start, end: len })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index_mut(&mut self, index: ops::RangeFrom<usize>) -> &mut [T] {
|
||||||
|
let len = self.len();
|
||||||
|
self.index_mut(ops::Range{ start: index.start, end: len })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<T> ops::IndexMut<RangeFull> for [T] {
|
impl<T> ops::IndexMut<RangeFull> for [T] {
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index_mut(&mut self, _index: &RangeFull) -> &mut [T] {
|
fn index_mut(&mut self, _index: &RangeFull) -> &mut [T] {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index_mut(&mut self, _index: RangeFull) -> &mut [T] {
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -763,37 +869,69 @@ unsafe impl<'a, T: Sync> Send for Iter<'a, T> {}
|
||||||
#[unstable(feature = "core")]
|
#[unstable(feature = "core")]
|
||||||
impl<'a, T> ops::Index<ops::Range<usize>> for Iter<'a, T> {
|
impl<'a, T> ops::Index<ops::Range<usize>> for Iter<'a, T> {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, index: &ops::Range<usize>) -> &[T] {
|
fn index(&self, index: &ops::Range<usize>) -> &[T] {
|
||||||
self.as_slice().index(index)
|
self.as_slice().index(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, index: ops::Range<usize>) -> &[T] {
|
||||||
|
self.as_slice().index(index)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "core")]
|
#[unstable(feature = "core")]
|
||||||
impl<'a, T> ops::Index<ops::RangeTo<usize>> for Iter<'a, T> {
|
impl<'a, T> ops::Index<ops::RangeTo<usize>> for Iter<'a, T> {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, index: &ops::RangeTo<usize>) -> &[T] {
|
fn index(&self, index: &ops::RangeTo<usize>) -> &[T] {
|
||||||
self.as_slice().index(index)
|
self.as_slice().index(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, index: ops::RangeTo<usize>) -> &[T] {
|
||||||
|
self.as_slice().index(index)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "core")]
|
#[unstable(feature = "core")]
|
||||||
impl<'a, T> ops::Index<ops::RangeFrom<usize>> for Iter<'a, T> {
|
impl<'a, T> ops::Index<ops::RangeFrom<usize>> for Iter<'a, T> {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, index: &ops::RangeFrom<usize>) -> &[T] {
|
fn index(&self, index: &ops::RangeFrom<usize>) -> &[T] {
|
||||||
self.as_slice().index(index)
|
self.as_slice().index(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, index: ops::RangeFrom<usize>) -> &[T] {
|
||||||
|
self.as_slice().index(index)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "core")]
|
#[unstable(feature = "core")]
|
||||||
impl<'a, T> ops::Index<RangeFull> for Iter<'a, T> {
|
impl<'a, T> ops::Index<RangeFull> for Iter<'a, T> {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, _index: &RangeFull) -> &[T] {
|
fn index(&self, _index: &RangeFull) -> &[T] {
|
||||||
self.as_slice()
|
self.as_slice()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, _index: RangeFull) -> &[T] {
|
||||||
|
self.as_slice()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T> Iter<'a, T> {
|
impl<'a, T> Iter<'a, T> {
|
||||||
|
@ -856,63 +994,126 @@ unsafe impl<'a, T: Send> Send for IterMut<'a, T> {}
|
||||||
#[unstable(feature = "core")]
|
#[unstable(feature = "core")]
|
||||||
impl<'a, T> ops::Index<ops::Range<usize>> for IterMut<'a, T> {
|
impl<'a, T> ops::Index<ops::Range<usize>> for IterMut<'a, T> {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, index: &ops::Range<usize>) -> &[T] {
|
fn index(&self, index: &ops::Range<usize>) -> &[T] {
|
||||||
self.index(&RangeFull).index(index)
|
self.index(&RangeFull).index(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, index: ops::Range<usize>) -> &[T] {
|
||||||
|
self.index(RangeFull).index(index)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[unstable(feature = "core")]
|
#[unstable(feature = "core")]
|
||||||
impl<'a, T> ops::Index<ops::RangeTo<usize>> for IterMut<'a, T> {
|
impl<'a, T> ops::Index<ops::RangeTo<usize>> for IterMut<'a, T> {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, index: &ops::RangeTo<usize>) -> &[T] {
|
fn index(&self, index: &ops::RangeTo<usize>) -> &[T] {
|
||||||
self.index(&RangeFull).index(index)
|
self.index(&RangeFull).index(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, index: ops::RangeTo<usize>) -> &[T] {
|
||||||
|
self.index(RangeFull).index(index)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[unstable(feature = "core")]
|
#[unstable(feature = "core")]
|
||||||
impl<'a, T> ops::Index<ops::RangeFrom<usize>> for IterMut<'a, T> {
|
impl<'a, T> ops::Index<ops::RangeFrom<usize>> for IterMut<'a, T> {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, index: &ops::RangeFrom<usize>) -> &[T] {
|
fn index(&self, index: &ops::RangeFrom<usize>) -> &[T] {
|
||||||
self.index(&RangeFull).index(index)
|
self.index(&RangeFull).index(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, index: ops::RangeFrom<usize>) -> &[T] {
|
||||||
|
self.index(RangeFull).index(index)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[unstable(feature = "core")]
|
#[unstable(feature = "core")]
|
||||||
impl<'a, T> ops::Index<RangeFull> for IterMut<'a, T> {
|
impl<'a, T> ops::Index<RangeFull> for IterMut<'a, T> {
|
||||||
type Output = [T];
|
type Output = [T];
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, _index: &RangeFull) -> &[T] {
|
fn index(&self, _index: &RangeFull) -> &[T] {
|
||||||
make_slice!(T => &[T]: self.ptr, self.end)
|
make_slice!(T => &[T]: self.ptr, self.end)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, _index: RangeFull) -> &[T] {
|
||||||
|
make_slice!(T => &[T]: self.ptr, self.end)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "core")]
|
#[unstable(feature = "core")]
|
||||||
impl<'a, T> ops::IndexMut<ops::Range<usize>> for IterMut<'a, T> {
|
impl<'a, T> ops::IndexMut<ops::Range<usize>> for IterMut<'a, T> {
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index_mut(&mut self, index: &ops::Range<usize>) -> &mut [T] {
|
fn index_mut(&mut self, index: &ops::Range<usize>) -> &mut [T] {
|
||||||
self.index_mut(&RangeFull).index_mut(index)
|
self.index_mut(&RangeFull).index_mut(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index_mut(&mut self, index: ops::Range<usize>) -> &mut [T] {
|
||||||
|
self.index_mut(RangeFull).index_mut(index)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[unstable(feature = "core")]
|
#[unstable(feature = "core")]
|
||||||
impl<'a, T> ops::IndexMut<ops::RangeTo<usize>> for IterMut<'a, T> {
|
impl<'a, T> ops::IndexMut<ops::RangeTo<usize>> for IterMut<'a, T> {
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index_mut(&mut self, index: &ops::RangeTo<usize>) -> &mut [T] {
|
fn index_mut(&mut self, index: &ops::RangeTo<usize>) -> &mut [T] {
|
||||||
self.index_mut(&RangeFull).index_mut(index)
|
self.index_mut(&RangeFull).index_mut(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index_mut(&mut self, index: ops::RangeTo<usize>) -> &mut [T] {
|
||||||
|
self.index_mut(RangeFull).index_mut(index)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[unstable(feature = "core")]
|
#[unstable(feature = "core")]
|
||||||
impl<'a, T> ops::IndexMut<ops::RangeFrom<usize>> for IterMut<'a, T> {
|
impl<'a, T> ops::IndexMut<ops::RangeFrom<usize>> for IterMut<'a, T> {
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index_mut(&mut self, index: &ops::RangeFrom<usize>) -> &mut [T] {
|
fn index_mut(&mut self, index: &ops::RangeFrom<usize>) -> &mut [T] {
|
||||||
self.index_mut(&RangeFull).index_mut(index)
|
self.index_mut(&RangeFull).index_mut(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index_mut(&mut self, index: ops::RangeFrom<usize>) -> &mut [T] {
|
||||||
|
self.index_mut(RangeFull).index_mut(index)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[unstable(feature = "core")]
|
#[unstable(feature = "core")]
|
||||||
impl<'a, T> ops::IndexMut<RangeFull> for IterMut<'a, T> {
|
impl<'a, T> ops::IndexMut<RangeFull> for IterMut<'a, T> {
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index_mut(&mut self, _index: &RangeFull) -> &mut [T] {
|
fn index_mut(&mut self, _index: &RangeFull) -> &mut [T] {
|
||||||
make_mut_slice!(T => &mut [T]: self.ptr, self.end)
|
make_mut_slice!(T => &mut [T]: self.ptr, self.end)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index_mut(&mut self, _index: RangeFull) -> &mut [T] {
|
||||||
|
make_mut_slice!(T => &mut [T]: self.ptr, self.end)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1203,6 +1203,7 @@ mod traits {
|
||||||
/// // byte 100 is outside the string
|
/// // byte 100 is outside the string
|
||||||
/// // &s[3 .. 100];
|
/// // &s[3 .. 100];
|
||||||
/// ```
|
/// ```
|
||||||
|
#[cfg(stage0)]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl ops::Index<ops::Range<usize>> for str {
|
impl ops::Index<ops::Range<usize>> for str {
|
||||||
type Output = str;
|
type Output = str;
|
||||||
|
@ -1219,6 +1220,49 @@ mod traits {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns a slice of the given string from the byte range
|
||||||
|
/// [`begin`..`end`).
|
||||||
|
///
|
||||||
|
/// This operation is `O(1)`.
|
||||||
|
///
|
||||||
|
/// Panics when `begin` and `end` do not point to valid characters
|
||||||
|
/// or point beyond the last character of the string.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// let s = "Löwe 老虎 Léopard";
|
||||||
|
/// assert_eq!(&s[0 .. 1], "L");
|
||||||
|
///
|
||||||
|
/// assert_eq!(&s[1 .. 9], "öwe 老");
|
||||||
|
///
|
||||||
|
/// // these will panic:
|
||||||
|
/// // byte 2 lies within `ö`:
|
||||||
|
/// // &s[2 ..3];
|
||||||
|
///
|
||||||
|
/// // byte 8 lies within `老`
|
||||||
|
/// // &s[1 .. 8];
|
||||||
|
///
|
||||||
|
/// // byte 100 is outside the string
|
||||||
|
/// // &s[3 .. 100];
|
||||||
|
/// ```
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
impl ops::Index<ops::Range<usize>> for str {
|
||||||
|
type Output = str;
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, index: ops::Range<usize>) -> &str {
|
||||||
|
// is_char_boundary checks that the index is in [0, .len()]
|
||||||
|
if index.start <= index.end &&
|
||||||
|
self.is_char_boundary(index.start) &&
|
||||||
|
self.is_char_boundary(index.end) {
|
||||||
|
unsafe { self.slice_unchecked(index.start, index.end) }
|
||||||
|
} else {
|
||||||
|
super::slice_error_fail(self, index.start, index.end)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns a slice of the string from the beginning to byte
|
/// Returns a slice of the string from the beginning to byte
|
||||||
/// `end`.
|
/// `end`.
|
||||||
///
|
///
|
||||||
|
@ -1229,6 +1273,8 @@ mod traits {
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl ops::Index<ops::RangeTo<usize>> for str {
|
impl ops::Index<ops::RangeTo<usize>> for str {
|
||||||
type Output = str;
|
type Output = str;
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, index: &ops::RangeTo<usize>) -> &str {
|
fn index(&self, index: &ops::RangeTo<usize>) -> &str {
|
||||||
// is_char_boundary checks that the index is in [0, .len()]
|
// is_char_boundary checks that the index is in [0, .len()]
|
||||||
|
@ -1238,6 +1284,17 @@ mod traits {
|
||||||
super::slice_error_fail(self, 0, index.end)
|
super::slice_error_fail(self, 0, index.end)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, index: ops::RangeTo<usize>) -> &str {
|
||||||
|
// is_char_boundary checks that the index is in [0, .len()]
|
||||||
|
if self.is_char_boundary(index.end) {
|
||||||
|
unsafe { self.slice_unchecked(0, index.end) }
|
||||||
|
} else {
|
||||||
|
super::slice_error_fail(self, 0, index.end)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a slice of the string from `begin` to its end.
|
/// Returns a slice of the string from `begin` to its end.
|
||||||
|
@ -1249,6 +1306,8 @@ mod traits {
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl ops::Index<ops::RangeFrom<usize>> for str {
|
impl ops::Index<ops::RangeFrom<usize>> for str {
|
||||||
type Output = str;
|
type Output = str;
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, index: &ops::RangeFrom<usize>) -> &str {
|
fn index(&self, index: &ops::RangeFrom<usize>) -> &str {
|
||||||
// is_char_boundary checks that the index is in [0, .len()]
|
// is_char_boundary checks that the index is in [0, .len()]
|
||||||
|
@ -1258,15 +1317,34 @@ mod traits {
|
||||||
super::slice_error_fail(self, index.start, self.len())
|
super::slice_error_fail(self, index.start, self.len())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, index: ops::RangeFrom<usize>) -> &str {
|
||||||
|
// is_char_boundary checks that the index is in [0, .len()]
|
||||||
|
if self.is_char_boundary(index.start) {
|
||||||
|
unsafe { self.slice_unchecked(index.start, self.len()) }
|
||||||
|
} else {
|
||||||
|
super::slice_error_fail(self, index.start, self.len())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl ops::Index<ops::RangeFull> for str {
|
impl ops::Index<ops::RangeFull> for str {
|
||||||
type Output = str;
|
type Output = str;
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, _index: &ops::RangeFull) -> &str {
|
fn index(&self, _index: &ops::RangeFull) -> &str {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, _index: ops::RangeFull) -> &str {
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1218,6 +1218,7 @@ impl Json {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
impl<'a> Index<&'a str> for Json {
|
impl<'a> Index<&'a str> for Json {
|
||||||
type Output = Json;
|
type Output = Json;
|
||||||
|
|
||||||
|
@ -1226,6 +1227,16 @@ impl<'a> Index<&'a str> for Json {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
impl<'a> Index<&'a str> for Json {
|
||||||
|
type Output = Json;
|
||||||
|
|
||||||
|
fn index(&self, idx: &'a str) -> &Json {
|
||||||
|
self.find(idx).unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
impl Index<uint> for Json {
|
impl Index<uint> for Json {
|
||||||
type Output = Json;
|
type Output = Json;
|
||||||
|
|
||||||
|
@ -1237,6 +1248,18 @@ impl Index<uint> for Json {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
impl Index<uint> for Json {
|
||||||
|
type Output = Json;
|
||||||
|
|
||||||
|
fn index<'a>(&'a self, idx: uint) -> &'a Json {
|
||||||
|
match self {
|
||||||
|
&Json::Array(ref v) => &v[idx],
|
||||||
|
_ => panic!("can only index Json with uint if it is an array")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The output of the streaming parser.
|
/// The output of the streaming parser.
|
||||||
#[derive(PartialEq, Clone, Debug)]
|
#[derive(PartialEq, Clone, Debug)]
|
||||||
pub enum JsonEvent {
|
pub enum JsonEvent {
|
||||||
|
|
|
@ -1088,7 +1088,7 @@ impl<K, V, S> HashMap<K, V, S>
|
||||||
/// Some(x) => *x = "b",
|
/// Some(x) => *x = "b",
|
||||||
/// None => (),
|
/// None => (),
|
||||||
/// }
|
/// }
|
||||||
/// assert_eq!(map[1], "b");
|
/// assert_eq!(map[&1], "b");
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub fn get_mut<Q: ?Sized>(&mut self, k: &Q) -> Option<&mut V>
|
pub fn get_mut<Q: ?Sized>(&mut self, k: &Q) -> Option<&mut V>
|
||||||
|
@ -1111,7 +1111,7 @@ impl<K, V, S> HashMap<K, V, S>
|
||||||
///
|
///
|
||||||
/// map.insert(37, "b");
|
/// map.insert(37, "b");
|
||||||
/// assert_eq!(map.insert(37, "c"), Some("b"));
|
/// assert_eq!(map.insert(37, "c"), Some("b"));
|
||||||
/// assert_eq!(map[37], "c");
|
/// assert_eq!(map[&37], "c");
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub fn insert(&mut self, k: K, v: V) -> Option<V> {
|
pub fn insert(&mut self, k: K, v: V) -> Option<V> {
|
||||||
|
@ -1244,6 +1244,7 @@ impl<K, V, S> Default for HashMap<K, V, S>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<K, Q: ?Sized, V, S> Index<Q> for HashMap<K, V, S>
|
impl<K, Q: ?Sized, V, S> Index<Q> for HashMap<K, V, S>
|
||||||
where K: Eq + Hash + Borrow<Q>,
|
where K: Eq + Hash + Borrow<Q>,
|
||||||
|
@ -1258,6 +1259,21 @@ impl<K, Q: ?Sized, V, S> Index<Q> for HashMap<K, V, S>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
impl<'a, K, Q: ?Sized, V, S> Index<&'a Q> for HashMap<K, V, S>
|
||||||
|
where K: Eq + Hash + Borrow<Q>,
|
||||||
|
Q: Eq + Hash,
|
||||||
|
S: HashState,
|
||||||
|
{
|
||||||
|
type Output = V;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, index: &Q) -> &V {
|
||||||
|
self.get(index).expect("no entry found for key")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// HashMap iterator.
|
/// HashMap iterator.
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub struct Iter<'a, K: 'a, V: 'a> {
|
pub struct Iter<'a, K: 'a, V: 'a> {
|
||||||
|
@ -2185,7 +2201,7 @@ mod test_map {
|
||||||
map.insert(2, 1);
|
map.insert(2, 1);
|
||||||
map.insert(3, 4);
|
map.insert(3, 4);
|
||||||
|
|
||||||
assert_eq!(map[2], 1);
|
assert_eq!(map[&2], 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -2197,7 +2213,7 @@ mod test_map {
|
||||||
map.insert(2, 1);
|
map.insert(2, 1);
|
||||||
map.insert(3, 4);
|
map.insert(3, 4);
|
||||||
|
|
||||||
map[4];
|
map[&4];
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -103,6 +103,7 @@ impl OsString {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl ops::Index<ops::RangeFull> for OsString {
|
impl ops::Index<ops::RangeFull> for OsString {
|
||||||
type Output = OsStr;
|
type Output = OsStr;
|
||||||
|
@ -113,6 +114,17 @@ impl ops::Index<ops::RangeFull> for OsString {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
impl ops::Index<ops::RangeFull> for OsString {
|
||||||
|
type Output = OsStr;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, _index: ops::RangeFull) -> &OsStr {
|
||||||
|
unsafe { mem::transmute(self.inner.as_slice()) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl ops::Deref for OsString {
|
impl ops::Deref for OsString {
|
||||||
type Target = OsStr;
|
type Target = OsStr;
|
||||||
|
|
|
@ -634,6 +634,7 @@ impl Wtf8 {
|
||||||
///
|
///
|
||||||
/// Panics when `begin` and `end` do not point to code point boundaries,
|
/// Panics when `begin` and `end` do not point to code point boundaries,
|
||||||
/// or point beyond the end of the string.
|
/// or point beyond the end of the string.
|
||||||
|
#[cfg(stage0)]
|
||||||
impl ops::Index<ops::Range<usize>> for Wtf8 {
|
impl ops::Index<ops::Range<usize>> for Wtf8 {
|
||||||
type Output = Wtf8;
|
type Output = Wtf8;
|
||||||
|
|
||||||
|
@ -650,12 +651,36 @@ impl ops::Index<ops::Range<usize>> for Wtf8 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return a slice of the given string for the byte range [`begin`..`end`).
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Panics when `begin` and `end` do not point to code point boundaries,
|
||||||
|
/// or point beyond the end of the string.
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
impl ops::Index<ops::Range<usize>> for Wtf8 {
|
||||||
|
type Output = Wtf8;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, range: ops::Range<usize>) -> &Wtf8 {
|
||||||
|
// is_code_point_boundary checks that the index is in [0, .len()]
|
||||||
|
if range.start <= range.end &&
|
||||||
|
is_code_point_boundary(self, range.start) &&
|
||||||
|
is_code_point_boundary(self, range.end) {
|
||||||
|
unsafe { slice_unchecked(self, range.start, range.end) }
|
||||||
|
} else {
|
||||||
|
slice_error_fail(self, range.start, range.end)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Return a slice of the given string from byte `begin` to its end.
|
/// Return a slice of the given string from byte `begin` to its end.
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// Panics when `begin` is not at a code point boundary,
|
/// Panics when `begin` is not at a code point boundary,
|
||||||
/// or is beyond the end of the string.
|
/// or is beyond the end of the string.
|
||||||
|
#[cfg(stage0)]
|
||||||
impl ops::Index<ops::RangeFrom<usize>> for Wtf8 {
|
impl ops::Index<ops::RangeFrom<usize>> for Wtf8 {
|
||||||
type Output = Wtf8;
|
type Output = Wtf8;
|
||||||
|
|
||||||
|
@ -670,12 +695,34 @@ impl ops::Index<ops::RangeFrom<usize>> for Wtf8 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return a slice of the given string from byte `begin` to its end.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Panics when `begin` is not at a code point boundary,
|
||||||
|
/// or is beyond the end of the string.
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
impl ops::Index<ops::RangeFrom<usize>> for Wtf8 {
|
||||||
|
type Output = Wtf8;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, range: ops::RangeFrom<usize>) -> &Wtf8 {
|
||||||
|
// is_code_point_boundary checks that the index is in [0, .len()]
|
||||||
|
if is_code_point_boundary(self, range.start) {
|
||||||
|
unsafe { slice_unchecked(self, range.start, self.len()) }
|
||||||
|
} else {
|
||||||
|
slice_error_fail(self, range.start, self.len())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Return a slice of the given string from its beginning to byte `end`.
|
/// Return a slice of the given string from its beginning to byte `end`.
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// Panics when `end` is not at a code point boundary,
|
/// Panics when `end` is not at a code point boundary,
|
||||||
/// or is beyond the end of the string.
|
/// or is beyond the end of the string.
|
||||||
|
#[cfg(stage0)]
|
||||||
impl ops::Index<ops::RangeTo<usize>> for Wtf8 {
|
impl ops::Index<ops::RangeTo<usize>> for Wtf8 {
|
||||||
type Output = Wtf8;
|
type Output = Wtf8;
|
||||||
|
|
||||||
|
@ -690,6 +737,28 @@ impl ops::Index<ops::RangeTo<usize>> for Wtf8 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return a slice of the given string from its beginning to byte `end`.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Panics when `end` is not at a code point boundary,
|
||||||
|
/// or is beyond the end of the string.
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
impl ops::Index<ops::RangeTo<usize>> for Wtf8 {
|
||||||
|
type Output = Wtf8;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, range: ops::RangeTo<usize>) -> &Wtf8 {
|
||||||
|
// is_code_point_boundary checks that the index is in [0, .len()]
|
||||||
|
if is_code_point_boundary(self, range.end) {
|
||||||
|
unsafe { slice_unchecked(self, 0, range.end) }
|
||||||
|
} else {
|
||||||
|
slice_error_fail(self, 0, range.end)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
impl ops::Index<ops::RangeFull> for Wtf8 {
|
impl ops::Index<ops::RangeFull> for Wtf8 {
|
||||||
type Output = Wtf8;
|
type Output = Wtf8;
|
||||||
|
|
||||||
|
@ -699,6 +768,16 @@ impl ops::Index<ops::RangeFull> for Wtf8 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
impl ops::Index<ops::RangeFull> for Wtf8 {
|
||||||
|
type Output = Wtf8;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn index(&self, _range: ops::RangeFull) -> &Wtf8 {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn decode_surrogate(second_byte: u8, third_byte: u8) -> u16 {
|
fn decode_surrogate(second_byte: u8, third_byte: u8) -> u16 {
|
||||||
// The first byte is assumed to be 0xED
|
// The first byte is assumed to be 0xED
|
||||||
|
|
Loading…
Reference in New Issue