1
Fork 0

Revert "Review and rebasing changes"

This reverts commit 6e0611a487.
This commit is contained in:
Aaron Turon 2014-10-02 11:47:38 -07:00
parent b2d4eb186e
commit 2f365ffdad
8 changed files with 42 additions and 103 deletions

View file

@ -44,8 +44,7 @@
//! //!
//! A number of traits add methods that allow you to accomplish tasks with slices. //! A number of traits add methods that allow you to accomplish tasks with slices.
//! These traits include `ImmutableSlice`, which is defined for `&[T]` types, //! These traits include `ImmutableSlice`, which is defined for `&[T]` types,
//! `MutableSlice`, defined for `&mut [T]` types, and `Slice` and `SliceMut` //! and `MutableSlice`, defined for `&mut [T]` types.
//! which are defined for `[T]`.
//! //!
//! An example is the `slice` method which enables slicing syntax `[a..b]` that //! An example is the `slice` method which enables slicing syntax `[a..b]` that
//! returns an immutable "view" into a `Vec` or another slice from the index //! returns an immutable "view" into a `Vec` or another slice from the index

View file

@ -927,7 +927,6 @@ impl<S: Str> Add<S, String> for String {
} }
} }
#[cfg(stage0)]
impl ops::Slice<uint, str> for String { impl ops::Slice<uint, str> for String {
#[inline] #[inline]
fn as_slice_<'a>(&'a self) -> &'a str { fn as_slice_<'a>(&'a self) -> &'a str {
@ -950,34 +949,6 @@ impl ops::Slice<uint, str> for String {
} }
} }
#[cfg(not(stage0))]
#[inline]
fn str_to_slice<'a, U: Str>(this: &'a U) -> &'a str {
this.as_slice()
}
#[cfg(not(stage0))]
impl ops::Slice<uint, str> for String {
#[inline]
fn as_slice<'a>(&'a self) -> &'a str {
str_to_slice(self)
}
#[inline]
fn slice_from<'a>(&'a self, from: &uint) -> &'a str {
self[][*from..]
}
#[inline]
fn slice_to<'a>(&'a self, to: &uint) -> &'a str {
self[][..*to]
}
#[inline]
fn slice<'a>(&'a self, from: &uint, to: &uint) -> &'a str {
self[][*from..*to]
}
}
/// Unsafe operations /// Unsafe operations
#[unstable = "waiting on raw module conventions"] #[unstable = "waiting on raw module conventions"]
pub mod raw { pub mod raw {

View file

@ -463,7 +463,6 @@ impl<T> Index<uint,T> for Vec<T> {
// Annoying helper function because there are two Slice::as_slice functions in // Annoying helper function because there are two Slice::as_slice functions in
// scope. // scope.
#[cfg(not(stage0))]
#[inline] #[inline]
fn slice_to_slice<'a, T, U: Slice<T>>(this: &'a U) -> &'a [T] { fn slice_to_slice<'a, T, U: Slice<T>>(this: &'a U) -> &'a [T] {
this.as_slice() this.as_slice()
@ -985,6 +984,7 @@ impl<T> Vec<T> {
/// assert!(vec[0..2] == [1, 2]); /// assert!(vec[0..2] == [1, 2]);
/// ``` /// ```
#[inline] #[inline]
#[deprecated = "use slicing syntax"]
pub fn slice<'a>(&'a self, start: uint, end: uint) -> &'a [T] { pub fn slice<'a>(&'a self, start: uint, end: uint) -> &'a [T] {
self[start..end] self[start..end]
} }
@ -1020,7 +1020,7 @@ impl<T> Vec<T> {
/// assert!(vec.tailn(2) == [3, 4]); /// assert!(vec.tailn(2) == [3, 4]);
/// ``` /// ```
#[inline] #[inline]
#[deprecated = "use slice_from"] #[deprecated = "use slicing syntax"]
pub fn tailn<'a>(&'a self, n: uint) -> &'a [T] { pub fn tailn<'a>(&'a self, n: uint) -> &'a [T] {
self[n..] self[n..]
} }
@ -1230,7 +1230,7 @@ impl<T> Vec<T> {
} }
/// Deprecated: use `slice_mut`. /// Deprecated: use `slice_mut`.
#[deprecated = "use slice_from"] #[deprecated = "use slicing syntax"]
pub fn mut_slice<'a>(&'a mut self, start: uint, end: uint) pub fn mut_slice<'a>(&'a mut self, start: uint, end: uint)
-> &'a mut [T] { -> &'a mut [T] {
self[mut start..end] self[mut start..end]
@ -1250,13 +1250,14 @@ impl<T> Vec<T> {
/// assert!(vec[mut 0..2] == [1, 2]); /// assert!(vec[mut 0..2] == [1, 2]);
/// ``` /// ```
#[inline] #[inline]
#[deprecated = "use slicing syntax"]
pub fn slice_mut<'a>(&'a mut self, start: uint, end: uint) pub fn slice_mut<'a>(&'a mut self, start: uint, end: uint)
-> &'a mut [T] { -> &'a mut [T] {
self[mut start..end] self[mut start..end]
} }
/// Deprecated: use "slice_from_mut". /// Deprecated: use "slice_from_mut".
#[deprecated = "use slice_from_mut"] #[deprecated = "use slicing syntax"]
pub fn mut_slice_from<'a>(&'a mut self, start: uint) -> &'a mut [T] { pub fn mut_slice_from<'a>(&'a mut self, start: uint) -> &'a mut [T] {
self[mut start..] self[mut start..]
} }
@ -1274,12 +1275,13 @@ impl<T> Vec<T> {
/// assert!(vec[mut 2..] == [3, 4]); /// assert!(vec[mut 2..] == [3, 4]);
/// ``` /// ```
#[inline] #[inline]
#[deprecated = "use slicing syntax"]
pub fn slice_from_mut<'a>(&'a mut self, start: uint) -> &'a mut [T] { pub fn slice_from_mut<'a>(&'a mut self, start: uint) -> &'a mut [T] {
self[mut start..] self[mut start..]
} }
/// Deprecated: use `slice_to_mut`. /// Deprecated: use `slice_to_mut`.
#[deprecated = "use slice_to_mut"] #[deprecated = "use slicing syntax"]
pub fn mut_slice_to<'a>(&'a mut self, end: uint) -> &'a mut [T] { pub fn mut_slice_to<'a>(&'a mut self, end: uint) -> &'a mut [T] {
self[mut ..end] self[mut ..end]
} }
@ -1297,6 +1299,7 @@ impl<T> Vec<T> {
/// assert!(vec[mut ..2] == [1, 2]); /// assert!(vec[mut ..2] == [1, 2]);
/// ``` /// ```
#[inline] #[inline]
#[deprecated = "use slicing syntax"]
pub fn slice_to_mut<'a>(&'a mut self, end: uint) -> &'a mut [T] { pub fn slice_to_mut<'a>(&'a mut self, end: uint) -> &'a mut [T] {
self[mut ..end] self[mut ..end]
} }
@ -1373,6 +1376,7 @@ impl<T> Vec<T> {
/// assert!(vec[1..] == [2, 3]); /// assert!(vec[1..] == [2, 3]);
/// ``` /// ```
#[inline] #[inline]
#[deprecated = "use slicing syntax"]
pub fn slice_from<'a>(&'a self, start: uint) -> &'a [T] { pub fn slice_from<'a>(&'a self, start: uint) -> &'a [T] {
self[start..] self[start..]
} }
@ -1390,6 +1394,7 @@ impl<T> Vec<T> {
/// assert!(vec[..2] == [1, 2]); /// assert!(vec[..2] == [1, 2]);
/// ``` /// ```
#[inline] #[inline]
#[deprecated = "use slicing syntax"]
pub fn slice_to<'a>(&'a self, end: uint) -> &'a [T] { pub fn slice_to<'a>(&'a self, end: uint) -> &'a [T] {
self[..end] self[..end]
} }

View file

@ -152,7 +152,7 @@ pub trait ImmutableSlice<'a, T> {
fn tail(&self) -> &'a [T]; fn tail(&self) -> &'a [T];
/// Returns all but the first `n' elements of a slice. /// Returns all but the first `n' elements of a slice.
#[deprecated = "use slice_from"] #[deprecated = "use slicing syntax"]
fn tailn(&self, n: uint) -> &'a [T]; fn tailn(&self, n: uint) -> &'a [T];
/// Returns all but the last element of a slice. /// Returns all but the last element of a slice.
@ -161,6 +161,7 @@ pub trait ImmutableSlice<'a, T> {
/// Returns all but the last `n' elements of a slice. /// Returns all but the last `n' elements of a slice.
#[deprecated = "use slice_to but note the arguments are different"] #[deprecated = "use slice_to but note the arguments are different"]
#[deprecated = "use slicing syntax, but note the arguments are different"]
fn initn(&self, n: uint) -> &'a [T]; fn initn(&self, n: uint) -> &'a [T];
/// Returns the last element of a slice, or `None` if it is empty. /// Returns the last element of a slice, or `None` if it is empty.
@ -320,7 +321,7 @@ impl<'a,T> ImmutableSlice<'a, T> for &'a [T] {
fn tail(&self) -> &'a [T] { (*self)[1..] } fn tail(&self) -> &'a [T] { (*self)[1..] }
#[inline] #[inline]
#[deprecated = "use slice_from"] #[deprecated = "use slicing syntax"]
fn tailn(&self, n: uint) -> &'a [T] { (*self)[n..] } fn tailn(&self, n: uint) -> &'a [T] { (*self)[n..] }
#[inline] #[inline]
@ -329,7 +330,7 @@ impl<'a,T> ImmutableSlice<'a, T> for &'a [T] {
} }
#[inline] #[inline]
#[deprecated = "use slice_to but note the arguments are different"] #[deprecated = "use slicing syntax but note the arguments are different"]
fn initn(&self, n: uint) -> &'a [T] { fn initn(&self, n: uint) -> &'a [T] {
(*self)[..self.len() - n] (*self)[..self.len() - n]
} }
@ -542,6 +543,7 @@ pub trait MutableSlice<'a, T> {
fn get_mut(self, index: uint) -> Option<&'a mut T>; fn get_mut(self, index: uint) -> Option<&'a mut T>;
/// Work with `self` as a mut slice. /// Work with `self` as a mut slice.
/// Primarily intended for getting a &mut [T] from a [T, ..N]. /// Primarily intended for getting a &mut [T] from a [T, ..N].
#[deprecated = "use slicing syntax"]
fn as_mut_slice(self) -> &'a mut [T]; fn as_mut_slice(self) -> &'a mut [T];
/// Deprecated: use `iter_mut`. /// Deprecated: use `iter_mut`.

View file

@ -1164,7 +1164,6 @@ pub mod traits {
fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) } fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) }
} }
#[cfg(stage0)]
impl ops::Slice<uint, str> for str { impl ops::Slice<uint, str> for str {
#[inline] #[inline]
fn as_slice_<'a>(&'a self) -> &'a str { fn as_slice_<'a>(&'a self) -> &'a str {
@ -1173,39 +1172,17 @@ pub mod traits {
#[inline] #[inline]
fn slice_from_<'a>(&'a self, from: &uint) -> &'a str { fn slice_from_<'a>(&'a self, from: &uint) -> &'a str {
super::slice_from_impl(&self, *from) self.slice_from(*from)
} }
#[inline] #[inline]
fn slice_to_<'a>(&'a self, to: &uint) -> &'a str { fn slice_to_<'a>(&'a self, to: &uint) -> &'a str {
super::slice_to_impl(&self, *to) self.slice_to(*to)
} }
#[inline] #[inline]
fn slice_<'a>(&'a self, from: &uint, to: &uint) -> &'a str { fn slice_<'a>(&'a self, from: &uint, to: &uint) -> &'a str {
super::slice_impl(&self, *from, *to) self.slice(*from, *to)
}
}
#[cfg(not(stage0))]
impl ops::Slice<uint, str> for str {
#[inline]
fn as_slice<'a>(&'a self) -> &'a str {
self
}
#[inline]
fn slice_from<'a>(&'a self, from: &uint) -> &'a str {
super::slice_from_impl(&self, *from)
}
#[inline]
fn slice_to<'a>(&'a self, to: &uint) -> &'a str {
super::slice_to_impl(&self, *to)
}
#[inline]
fn slice<'a>(&'a self, from: &uint, to: &uint) -> &'a str {
super::slice_impl(&self, *from, *to)
} }
} }
} }
@ -1858,38 +1835,6 @@ fn slice_error_fail(s: &str, begin: uint, end: uint) -> ! {
begin, end, s); begin, end, s);
} }
#[inline]
fn slice_impl<'a>(this: &&'a str, begin: uint, end: uint) -> &'a str {
// is_char_boundary checks that the index is in [0, .len()]
if begin <= end &&
this.is_char_boundary(begin) &&
this.is_char_boundary(end) {
unsafe { raw::slice_unchecked(*this, begin, end) }
} else {
slice_error_fail(*this, begin, end)
}
}
#[inline]
fn slice_from_impl<'a>(this: &&'a str, begin: uint) -> &'a str {
// is_char_boundary checks that the index is in [0, .len()]
if this.is_char_boundary(begin) {
unsafe { raw::slice_unchecked(*this, begin, this.len()) }
} else {
slice_error_fail(*this, begin, this.len())
}
}
#[inline]
fn slice_to_impl<'a>(this: &&'a str, end: uint) -> &'a str {
// is_char_boundary checks that the index is in [0, .len()]
if this.is_char_boundary(end) {
unsafe { raw::slice_unchecked(*this, 0, end) }
} else {
slice_error_fail(*this, 0, end)
}
}
impl<'a> StrSlice<'a> for &'a str { impl<'a> StrSlice<'a> for &'a str {
#[inline] #[inline]
fn contains<'a>(&self, needle: &'a str) -> bool { fn contains<'a>(&self, needle: &'a str) -> bool {
@ -1993,17 +1938,34 @@ impl<'a> StrSlice<'a> for &'a str {
#[inline] #[inline]
fn slice(&self, begin: uint, end: uint) -> &'a str { fn slice(&self, begin: uint, end: uint) -> &'a str {
slice_impl(self, begin, end) // is_char_boundary checks that the index is in [0, .len()]
if begin <= end &&
self.is_char_boundary(begin) &&
self.is_char_boundary(end) {
unsafe { raw::slice_unchecked(*self, begin, end) }
} else {
slice_error_fail(*self, begin, end)
}
} }
#[inline] #[inline]
fn slice_from(&self, begin: uint) -> &'a str { fn slice_from(&self, begin: uint) -> &'a str {
slice_from_impl(self, begin) // is_char_boundary checks that the index is in [0, .len()]
if self.is_char_boundary(begin) {
unsafe { raw::slice_unchecked(*self, begin, self.len()) }
} else {
slice_error_fail(*self, begin, self.len())
}
} }
#[inline] #[inline]
fn slice_to(&self, end: uint) -> &'a str { fn slice_to(&self, end: uint) -> &'a str {
slice_to_impl(self, end) // is_char_boundary checks that the index is in [0, .len()]
if self.is_char_boundary(end) {
unsafe { raw::slice_unchecked(*self, 0, end) }
} else {
slice_error_fail(*self, 0, end)
}
} }
fn slice_chars(&self, begin: uint, end: uint) -> &'a str { fn slice_chars(&self, begin: uint, end: uint) -> &'a str {

View file

@ -448,7 +448,7 @@ impl rtio::RtioPipe for UnixStream {
} }
let ret = unsafe { let ret = unsafe {
libc::WriteFile(self.handle(), libc::WriteFile(self.handle(),
buf[offset..].as_ptr() as libc::LPVOID, buf.slice_from(offset).as_ptr() as libc::LPVOID,
(buf.len() - offset) as libc::DWORD, (buf.len() - offset) as libc::DWORD,
&mut bytes_written, &mut bytes_written,
&mut overlapped) &mut overlapped)

View file

@ -144,7 +144,7 @@ pub mod windows {
use option::{None, Option}; use option::{None, Option};
use option; use option;
use os::TMPBUF_SZ; use os::TMPBUF_SZ;
use slice::MutableSlice; use slice::{MutableSlice, ImmutableSlice};
use string::String; use string::String;
use str::StrSlice; use str::StrSlice;
use vec::Vec; use vec::Vec;

View file

@ -999,7 +999,7 @@ mod imp {
let bytes = cstr.as_bytes(); let bytes = cstr.as_bytes();
match cstr.as_str() { match cstr.as_str() {
Some(s) => try!(super::demangle(w, s)), Some(s) => try!(super::demangle(w, s)),
None => try!(w.write(bytes[..bytes.len()-1])), None => try!(w.write(bytes.slice_to(bytes.len() - 1))),
} }
} }
try!(w.write(['\n' as u8])); try!(w.write(['\n' as u8]));