auto merge of #19747 : alexcrichton/rust/slice-one-trait, r=brson

This commit collapses the various prelude traits for slices into just one trait:

* SlicePrelude/SliceAllocPrelude => SliceExt
* CloneSlicePrelude/CloneSliceAllocPrelude => CloneSliceExt
* OrdSlicePrelude/OrdSliceAllocPrelude => OrdSliceExt
* PartialEqSlicePrelude => PartialEqSliceExt
This commit is contained in:
bors 2014-12-16 01:32:33 +00:00
commit b497f05008
42 changed files with 782 additions and 539 deletions

View File

@ -289,7 +289,7 @@ def emit_bsearch_range_table(f):
f.write("""
fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
use core::cmp::Ordering::{Equal, Less, Greater};
use core::slice::SlicePrelude;
use core::slice::SliceExt;
r.binary_search(|&(lo,hi)| {
if lo <= c && c <= hi { Equal }
else if hi < c { Less }
@ -347,7 +347,7 @@ def emit_conversions_module(f, lowerupper, upperlower):
f.write("pub mod conversions {")
f.write("""
use core::cmp::Ordering::{Equal, Less, Greater};
use core::slice::SlicePrelude;
use core::slice::SliceExt;
use core::option::Option;
use core::option::Option::{Some, None};
use core::slice;
@ -386,8 +386,8 @@ def emit_conversions_module(f, lowerupper, upperlower):
def emit_grapheme_module(f, grapheme_table, grapheme_cats):
f.write("""pub mod grapheme {
use core::slice::SlicePrelude;
use core::kinds::Copy;
use core::slice::SliceExt;
pub use self::GraphemeCat::*;
use core::slice;
@ -431,7 +431,7 @@ def emit_charwidth_module(f, width_table):
f.write("pub mod charwidth {\n")
f.write(" use core::option::Option;\n")
f.write(" use core::option::Option::{Some, None};\n")
f.write(" use core::slice::SlicePrelude;\n")
f.write(" use core::slice::SliceExt;\n")
f.write(" use core::slice;\n")
f.write("""
fn bsearch_range_value_table(c: char, is_cjk: bool, r: &'static [(char, char, u8, u8)]) -> u8 {
@ -531,7 +531,7 @@ def emit_norm_module(f, canon, compat, combine, norm_props):
f.write("""
fn bsearch_range_value_table(c: char, r: &'static [(char, char, u8)]) -> u8 {
use core::cmp::Ordering::{Equal, Less, Greater};
use core::slice::SlicePrelude;
use core::slice::SliceExt;
use core::slice;
match r.binary_search(|&(lo, hi, _)| {
if lo <= c && c <= hi { Equal }

View File

@ -297,7 +297,7 @@ mod tests {
use core::kinds::Sized;
use std::mem;
use slice::SlicePrelude;
use slice::SliceExt;
use super::{Hash, Hasher, Writer};
struct MyWriterHasher;

View File

@ -276,7 +276,7 @@ mod tests {
use str::Str;
use string::String;
use slice::{AsSlice, SlicePrelude};
use slice::{AsSlice, SliceExt};
use vec::Vec;
use super::super::{Hash, Writer};

View File

@ -24,7 +24,7 @@
#![allow(unknown_features)]
#![feature(macro_rules, default_type_params, phase, globs)]
#![feature(unsafe_destructor, import_shadowing, slicing_syntax)]
#![feature(tuple_indexing, unboxed_closures)]
#![feature(unboxed_closures)]
#![no_std]
#[phase(plugin, link)] extern crate core;

View File

@ -43,7 +43,7 @@
//! ## Traits
//!
//! A number of traits add methods that allow you to accomplish tasks
//! with slices, the most important being `SlicePrelude`. Other traits
//! with slices, the most important being `SliceExt`. Other traits
//! apply only to slices of elements satisfying certain bounds (like
//! `Ord`).
//!
@ -87,10 +87,10 @@
#![doc(primitive = "slice")]
use self::Direction::*;
use alloc::boxed::Box;
use core::borrow::{BorrowFrom, BorrowFromMut, ToOwned};
use core::cmp;
use core::iter::{range_step, MultiplicativeIterator};
use core::kinds::{Copy, Sized};
use core::mem::size_of;
use core::mem;
@ -98,15 +98,16 @@ use core::ops::FnMut;
use core::prelude::{Clone, Greater, Iterator, IteratorExt, Less, None, Option};
use core::prelude::{Ord, Ordering, RawPtr, Some, range};
use core::ptr;
use core::iter::{range_step, MultiplicativeIterator};
use core::slice as core_slice;
use self::Direction::*;
use vec::Vec;
pub use core::slice::{Chunks, AsSlice, SlicePrelude, PartialEqSlicePrelude};
pub use core::slice::{OrdSlicePrelude, SlicePrelude, Items, MutItems};
pub use core::slice::{Chunks, AsSlice, SplitsN, Windows};
pub use core::slice::{Items, MutItems, PartialEqSliceExt};
pub use core::slice::{ImmutableIntSlice, MutableIntSlice};
pub use core::slice::{MutSplits, MutChunks, Splits};
pub use core::slice::{bytes, mut_ref_slice, ref_slice, CloneSlicePrelude};
pub use core::slice::{bytes, mut_ref_slice, ref_slice};
pub use core::slice::{from_raw_buf, from_raw_mut_buf, BinarySearchResult};
// Functional utilities
@ -274,12 +275,12 @@ impl<T: Clone> Iterator<Vec<T>> for Permutations<T> {
}
/// Extension methods for boxed slices.
pub trait BoxedSlicePrelude<T> {
pub trait BoxedSliceExt<T> {
/// Convert `self` into a vector without clones or allocation.
fn into_vec(self) -> Vec<T>;
}
impl<T> BoxedSlicePrelude<T> for Box<[T]> {
impl<T> BoxedSliceExt<T> for Box<[T]> {
#[experimental]
fn into_vec(mut self) -> Vec<T> {
unsafe {
@ -291,7 +292,7 @@ impl<T> BoxedSlicePrelude<T> for Box<[T]> {
}
/// Allocating extension methods for slices containing `Clone` elements.
pub trait CloneSliceAllocPrelude<T> for Sized? {
pub trait CloneSliceExt<T> for Sized? {
/// Copies `self` into a new `Vec`.
fn to_vec(&self) -> Vec<T>;
@ -324,9 +325,28 @@ pub trait CloneSliceAllocPrelude<T> for Sized? {
/// assert_eq!(Some(vec![3i, 1, 2]), perms.next());
/// ```
fn permutations(&self) -> Permutations<T>;
/// Copies as many elements from `src` as it can into `self` (the
/// shorter of `self.len()` and `src.len()`). Returns the number
/// of elements copied.
///
/// # Example
///
/// ```rust
/// let mut dst = [0i, 0, 0];
/// let src = [1i, 2];
///
/// assert!(dst.clone_from_slice(&src) == 2);
/// assert!(dst == [1, 2, 0]);
///
/// let src2 = [3i, 4, 5, 6];
/// assert!(dst.clone_from_slice(&src2) == 3);
/// assert!(dst == [3i, 4, 5]);
/// ```
fn clone_from_slice(&mut self, &[T]) -> uint;
}
impl<T: Clone> CloneSliceAllocPrelude<T> for [T] {
impl<T: Clone> CloneSliceExt<T> for [T] {
/// Returns a copy of `v`.
#[inline]
fn to_vec(&self) -> Vec<T> {
@ -360,6 +380,9 @@ impl<T: Clone> CloneSliceAllocPrelude<T> for [T] {
}
}
fn clone_from_slice(&mut self, src: &[T]) -> uint {
core_slice::CloneSliceExt::clone_from_slice(self, src)
}
}
fn insertion_sort<T, F>(v: &mut [T], mut compare: F) where F: FnMut(&T, &T) -> Ordering {
@ -567,7 +590,7 @@ fn merge_sort<T, F>(v: &mut [T], mut compare: F) where F: FnMut(&T, &T) -> Order
/// Allocating extension methods for slices on Ord values.
#[experimental = "likely to merge with other traits"]
pub trait OrdSliceAllocPrelude<T> for Sized? {
pub trait OrdSliceExt<T> for Sized? {
/// Sorts the slice, in place.
///
/// This is equivalent to `self.sort_by(|a, b| a.cmp(b))`.
@ -582,19 +605,95 @@ pub trait OrdSliceAllocPrelude<T> for Sized? {
/// ```
#[experimental]
fn sort(&mut self);
/// Binary search a sorted slice for a given element.
///
/// If the value is found then `Found` is returned, containing the
/// index of the matching element; if the value is not found then
/// `NotFound` is returned, containing the index where a matching
/// element could be inserted while maintaining sorted order.
///
/// # Example
///
/// Looks up a series of four elements. The first is found, with a
/// uniquely determined position; the second and third are not
/// found; the fourth could match any position in `[1,4]`.
///
/// ```rust
/// use std::slice::BinarySearchResult::{Found, NotFound};
/// let s = [0i, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
/// let s = s.as_slice();
///
/// assert_eq!(s.binary_search_elem(&13), Found(9));
/// assert_eq!(s.binary_search_elem(&4), NotFound(7));
/// assert_eq!(s.binary_search_elem(&100), NotFound(13));
/// let r = s.binary_search_elem(&1);
/// assert!(match r { Found(1...4) => true, _ => false, });
/// ```
#[unstable = "name likely to change"]
fn binary_search_elem(&self, x: &T) -> BinarySearchResult;
/// Mutates the slice to the next lexicographic permutation.
///
/// Returns `true` if successful and `false` if the slice is at the
/// last-ordered permutation.
///
/// # Example
///
/// ```rust
/// let v: &mut [_] = &mut [0i, 1, 2];
/// v.next_permutation();
/// let b: &mut [_] = &mut [0i, 2, 1];
/// assert!(v == b);
/// v.next_permutation();
/// let b: &mut [_] = &mut [1i, 0, 2];
/// assert!(v == b);
/// ```
#[experimental]
fn next_permutation(&mut self) -> bool;
/// Mutates the slice to the previous lexicographic permutation.
///
/// Returns `true` if successful and `false` if the slice is at the
/// first-ordered permutation.
///
/// # Example
///
/// ```rust
/// let v: &mut [_] = &mut [1i, 0, 2];
/// v.prev_permutation();
/// let b: &mut [_] = &mut [0i, 2, 1];
/// assert!(v == b);
/// v.prev_permutation();
/// let b: &mut [_] = &mut [0i, 1, 2];
/// assert!(v == b);
/// ```
#[experimental]
fn prev_permutation(&mut self) -> bool;
}
impl<T: Ord> OrdSliceAllocPrelude<T> for [T] {
#[experimental]
impl<T: Ord> OrdSliceExt<T> for [T] {
#[inline]
fn sort(&mut self) {
self.sort_by(|a, b| a.cmp(b))
}
fn binary_search_elem(&self, x: &T) -> BinarySearchResult {
core_slice::OrdSliceExt::binary_search_elem(self, x)
}
fn next_permutation(&mut self) -> bool {
core_slice::OrdSliceExt::next_permutation(self)
}
fn prev_permutation(&mut self) -> bool {
core_slice::OrdSliceExt::prev_permutation(self)
}
}
/// Allocating extension methods for slices.
#[experimental = "likely to merge with other traits"]
pub trait SliceAllocPrelude<T> for Sized? {
pub trait SliceExt<T> for Sized? {
/// Sorts the slice, in place, using `compare` to compare
/// elements.
///
@ -636,9 +735,376 @@ pub trait SliceAllocPrelude<T> for Sized? {
/// assert!(a == [6i, 7, 8, 4, 5]);
/// ```
fn move_from(&mut self, src: Vec<T>, start: uint, end: uint) -> uint;
/// Returns a subslice spanning the interval [`start`, `end`).
///
/// Panics when the end of the new slice lies beyond the end of the
/// original slice (i.e. when `end > self.len()`) or when `start > end`.
///
/// Slicing with `start` equal to `end` yields an empty slice.
#[unstable = "waiting on final error conventions/slicing syntax"]
fn slice(&self, start: uint, end: uint) -> &[T];
/// Returns a subslice from `start` to the end of the slice.
///
/// Panics when `start` is strictly greater than the length of the original slice.
///
/// Slicing from `self.len()` yields an empty slice.
#[unstable = "waiting on final error conventions/slicing syntax"]
fn slice_from(&self, start: uint) -> &[T];
/// Returns a subslice from the start of the slice to `end`.
///
/// Panics when `end` is strictly greater than the length of the original slice.
///
/// Slicing to `0` yields an empty slice.
#[unstable = "waiting on final error conventions/slicing syntax"]
fn slice_to(&self, end: uint) -> &[T];
/// Divides one slice into two at an index.
///
/// The first will contain all indices from `[0, mid)` (excluding
/// the index `mid` itself) and the second will contain all
/// indices from `[mid, len)` (excluding the index `len` itself).
///
/// Panics if `mid > len`.
#[unstable = "waiting on final error conventions"]
fn split_at(&self, mid: uint) -> (&[T], &[T]);
/// Returns an iterator over the slice
#[unstable = "iterator type may change"]
fn iter(&self) -> Items<T>;
/// Returns an iterator over subslices separated by elements that match
/// `pred`. The matched element is not contained in the subslices.
#[unstable = "iterator type may change, waiting on unboxed closures"]
fn split<F>(&self, pred: F) -> Splits<T, F>
where F: FnMut(&T) -> bool;
/// Returns an iterator over subslices separated by elements that match
/// `pred`, limited to splitting at most `n` times. The matched element is
/// not contained in the subslices.
#[unstable = "iterator type may change"]
fn splitn<F>(&self, n: uint, pred: F) -> SplitsN<Splits<T, F>>
where F: FnMut(&T) -> bool;
/// Returns an iterator over subslices separated by elements that match
/// `pred` limited to splitting at most `n` times. This starts at the end of
/// the slice and works backwards. The matched element is not contained in
/// the subslices.
#[unstable = "iterator type may change"]
fn rsplitn<F>(&self, n: uint, pred: F) -> SplitsN<Splits<T, F>>
where F: FnMut(&T) -> bool;
/// Returns an iterator over all contiguous windows of length
/// `size`. The windows overlap. If the slice is shorter than
/// `size`, the iterator returns no values.
///
/// # Panics
///
/// Panics if `size` is 0.
///
/// # Example
///
/// Print the adjacent pairs of a slice (i.e. `[1,2]`, `[2,3]`,
/// `[3,4]`):
///
/// ```rust
/// let v = &[1i, 2, 3, 4];
/// for win in v.windows(2) {
/// println!("{}", win);
/// }
/// ```
#[unstable = "iterator type may change"]
fn windows(&self, size: uint) -> Windows<T>;
/// Returns an iterator over `size` elements of the slice at a
/// time. The chunks do not overlap. If `size` does not divide the
/// length of the slice, then the last chunk will not have length
/// `size`.
///
/// # Panics
///
/// Panics if `size` is 0.
///
/// # Example
///
/// Print the slice two elements at a time (i.e. `[1,2]`,
/// `[3,4]`, `[5]`):
///
/// ```rust
/// let v = &[1i, 2, 3, 4, 5];
/// for win in v.chunks(2) {
/// println!("{}", win);
/// }
/// ```
#[unstable = "iterator type may change"]
fn chunks(&self, size: uint) -> Chunks<T>;
/// Returns the element of a slice at the given index, or `None` if the
/// index is out of bounds.
#[unstable = "waiting on final collection conventions"]
fn get(&self, index: uint) -> Option<&T>;
/// Returns the first element of a slice, or `None` if it is empty.
#[unstable = "name may change"]
fn head(&self) -> Option<&T>;
/// Returns all but the first element of a slice.
#[unstable = "name may change"]
fn tail(&self) -> &[T];
/// Returns all but the last element of a slice.
#[unstable = "name may change"]
fn init(&self) -> &[T];
/// Returns the last element of a slice, or `None` if it is empty.
#[unstable = "name may change"]
fn last(&self) -> Option<&T>;
/// Returns a pointer to the element at the given index, without doing
/// bounds checking.
#[unstable]
unsafe fn unsafe_get(&self, index: uint) -> &T;
/// Returns an unsafe pointer to the slice's buffer
///
/// The caller must ensure that the slice outlives the pointer this
/// function returns, or else it will end up pointing to garbage.
///
/// Modifying the slice may cause its buffer to be reallocated, which
/// would also make any pointers to it invalid.
#[unstable]
fn as_ptr(&self) -> *const T;
/// Binary search a sorted slice with a comparator function.
///
/// The comparator function should implement an order consistent
/// with the sort order of the underlying slice, returning an
/// order code that indicates whether its argument is `Less`,
/// `Equal` or `Greater` the desired target.
///
/// If a matching value is found then returns `Found`, containing
/// the index for the matched element; if no match is found then
/// `NotFound` is returned, containing the index where a matching
/// element could be inserted while maintaining sorted order.
///
/// # Example
///
/// Looks up a series of four elements. The first is found, with a
/// uniquely determined position; the second and third are not
/// found; the fourth could match any position in `[1,4]`.
///
/// ```rust
/// use std::slice::BinarySearchResult::{Found, NotFound};
/// let s = [0i, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
/// let s = s.as_slice();
///
/// let seek = 13;
/// assert_eq!(s.binary_search(|probe| probe.cmp(&seek)), Found(9));
/// let seek = 4;
/// assert_eq!(s.binary_search(|probe| probe.cmp(&seek)), NotFound(7));
/// let seek = 100;
/// assert_eq!(s.binary_search(|probe| probe.cmp(&seek)), NotFound(13));
/// let seek = 1;
/// let r = s.binary_search(|probe| probe.cmp(&seek));
/// assert!(match r { Found(1...4) => true, _ => false, });
/// ```
#[unstable = "waiting on unboxed closures"]
fn binary_search<F>(&self, f: F) -> BinarySearchResult
where F: FnMut(&T) -> Ordering;
/// Return the number of elements in the slice
///
/// # Example
///
/// ```
/// let a = [1i, 2, 3];
/// assert_eq!(a.len(), 3);
/// ```
#[experimental = "not triaged yet"]
fn len(&self) -> uint;
/// Returns true if the slice has a length of 0
///
/// # Example
///
/// ```
/// let a = [1i, 2, 3];
/// assert!(!a.is_empty());
/// ```
#[inline]
#[experimental = "not triaged yet"]
fn is_empty(&self) -> bool { self.len() == 0 }
/// Returns a mutable reference to the element at the given index,
/// or `None` if the index is out of bounds
#[unstable = "waiting on final error conventions"]
fn get_mut(&mut self, index: uint) -> Option<&mut T>;
/// Work with `self` as a mut slice.
/// Primarily intended for getting a &mut [T] from a [T, ..N].
fn as_mut_slice(&mut self) -> &mut [T];
/// Returns a mutable subslice spanning the interval [`start`, `end`).
///
/// Panics when the end of the new slice lies beyond the end of the
/// original slice (i.e. when `end > self.len()`) or when `start > end`.
///
/// Slicing with `start` equal to `end` yields an empty slice.
#[unstable = "waiting on final error conventions"]
fn slice_mut(&mut self, start: uint, end: uint) -> &mut [T];
/// Returns a mutable subslice from `start` to the end of the slice.
///
/// Panics when `start` is strictly greater than the length of the original slice.
///
/// Slicing from `self.len()` yields an empty slice.
#[unstable = "waiting on final error conventions"]
fn slice_from_mut(&mut self, start: uint) -> &mut [T];
/// Returns a mutable subslice from the start of the slice to `end`.
///
/// Panics when `end` is strictly greater than the length of the original slice.
///
/// Slicing to `0` yields an empty slice.
#[unstable = "waiting on final error conventions"]
fn slice_to_mut(&mut self, end: uint) -> &mut [T];
/// Returns an iterator that allows modifying each value
#[unstable = "waiting on iterator type name conventions"]
fn iter_mut(&mut self) -> MutItems<T>;
/// Returns a mutable pointer to the first element of a slice, or `None` if it is empty
#[unstable = "name may change"]
fn head_mut(&mut self) -> Option<&mut T>;
/// Returns all but the first element of a mutable slice
#[unstable = "name may change"]
fn tail_mut(&mut self) -> &mut [T];
/// Returns all but the last element of a mutable slice
#[unstable = "name may change"]
fn init_mut(&mut self) -> &mut [T];
/// Returns a mutable pointer to the last item in the slice.
#[unstable = "name may change"]
fn last_mut(&mut self) -> Option<&mut T>;
/// Returns an iterator over mutable subslices separated by elements that
/// match `pred`. The matched element is not contained in the subslices.
#[unstable = "waiting on unboxed closures, iterator type name conventions"]
fn split_mut<F>(&mut self, pred: F) -> MutSplits<T, F>
where F: FnMut(&T) -> bool;
/// Returns an iterator over subslices separated by elements that match
/// `pred`, limited to splitting at most `n` times. The matched element is
/// not contained in the subslices.
#[unstable = "waiting on unboxed closures, iterator type name conventions"]
fn splitn_mut<F>(&mut self, n: uint, pred: F) -> SplitsN<MutSplits<T, F>>
where F: FnMut(&T) -> bool;
/// Returns an iterator over subslices separated by elements that match
/// `pred` limited to splitting at most `n` times. This starts at the end of
/// the slice and works backwards. The matched element is not contained in
/// the subslices.
#[unstable = "waiting on unboxed closures, iterator type name conventions"]
fn rsplitn_mut<F>(&mut self, n: uint, pred: F) -> SplitsN<MutSplits<T, F>>
where F: FnMut(&T) -> bool;
/// Returns an iterator over `chunk_size` elements of the slice at a time.
/// The chunks are mutable and do not overlap. If `chunk_size` does
/// not divide the length of the slice, then the last chunk will not
/// have length `chunk_size`.
///
/// # Panics
///
/// Panics if `chunk_size` is 0.
#[unstable = "waiting on iterator type name conventions"]
fn chunks_mut(&mut self, chunk_size: uint) -> MutChunks<T>;
/// Swaps two elements in a slice.
///
/// Panics if `a` or `b` are out of bounds.
///
/// # Arguments
///
/// * a - The index of the first element
/// * b - The index of the second element
///
/// # Example
///
/// ```rust
/// let mut v = ["a", "b", "c", "d"];
/// v.swap(1, 3);
/// assert!(v == ["a", "d", "c", "b"]);
/// ```
#[unstable = "waiting on final error conventions"]
fn swap(&mut self, a: uint, b: uint);
/// Divides one `&mut` into two at an index.
///
/// The first will contain all indices from `[0, mid)` (excluding
/// the index `mid` itself) and the second will contain all
/// indices from `[mid, len)` (excluding the index `len` itself).
///
/// Panics if `mid > len`.
///
/// # Example
///
/// ```rust
/// let mut v = [1i, 2, 3, 4, 5, 6];
///
/// // scoped to restrict the lifetime of the borrows
/// {
/// let (left, right) = v.split_at_mut(0);
/// assert!(left == []);
/// assert!(right == [1i, 2, 3, 4, 5, 6]);
/// }
///
/// {
/// let (left, right) = v.split_at_mut(2);
/// assert!(left == [1i, 2]);
/// assert!(right == [3i, 4, 5, 6]);
/// }
///
/// {
/// let (left, right) = v.split_at_mut(6);
/// assert!(left == [1i, 2, 3, 4, 5, 6]);
/// assert!(right == []);
/// }
/// ```
#[unstable = "waiting on final error conventions"]
fn split_at_mut(&mut self, mid: uint) -> (&mut [T], &mut [T]);
/// Reverse the order of elements in a slice, in place.
///
/// # Example
///
/// ```rust
/// let mut v = [1i, 2, 3];
/// v.reverse();
/// assert!(v == [3i, 2, 1]);
/// ```
#[experimental = "may be moved to iterators instead"]
fn reverse(&mut self);
/// Returns an unsafe mutable pointer to the element in index
#[experimental = "waiting on unsafe conventions"]
unsafe fn unsafe_mut(&mut self, index: uint) -> &mut T;
/// Return an unsafe mutable pointer to the slice's buffer.
///
/// The caller must ensure that the slice outlives the pointer this
/// function returns, or else it will end up pointing to garbage.
///
/// Modifying the slice may cause its buffer to be reallocated, which
/// would also make any pointers to it invalid.
#[inline]
#[unstable]
fn as_mut_ptr(&mut self) -> *mut T;
}
impl<T> SliceAllocPrelude<T> for [T] {
impl<T> SliceExt<T> for [T] {
#[inline]
fn sort_by<F>(&mut self, compare: F) where F: FnMut(&T, &T) -> Ordering {
merge_sort(self, compare)
@ -651,6 +1117,208 @@ impl<T> SliceAllocPrelude<T> for [T] {
}
cmp::min(self.len(), end-start)
}
#[inline]
fn slice<'a>(&'a self, start: uint, end: uint) -> &'a [T] {
core_slice::SliceExt::slice(self, start, end)
}
#[inline]
fn slice_from<'a>(&'a self, start: uint) -> &'a [T] {
core_slice::SliceExt::slice_from(self, start)
}
#[inline]
fn slice_to<'a>(&'a self, end: uint) -> &'a [T] {
core_slice::SliceExt::slice_to(self, end)
}
#[inline]
fn split_at<'a>(&'a self, mid: uint) -> (&'a [T], &'a [T]) {
core_slice::SliceExt::split_at(self, mid)
}
#[inline]
fn iter<'a>(&'a self) -> Items<'a, T> {
core_slice::SliceExt::iter(self)
}
#[inline]
fn split<F>(&self, pred: F) -> Splits<T, F>
where F: FnMut(&T) -> bool {
core_slice::SliceExt::split(self, pred)
}
#[inline]
fn splitn<F>(&self, n: uint, pred: F) -> SplitsN<Splits<T, F>>
where F: FnMut(&T) -> bool {
core_slice::SliceExt::splitn(self, n, pred)
}
#[inline]
fn rsplitn<F>(&self, n: uint, pred: F) -> SplitsN<Splits<T, F>>
where F: FnMut(&T) -> bool {
core_slice::SliceExt::rsplitn(self, n, pred)
}
#[inline]
fn windows<'a>(&'a self, size: uint) -> Windows<'a, T> {
core_slice::SliceExt::windows(self, size)
}
#[inline]
fn chunks<'a>(&'a self, size: uint) -> Chunks<'a, T> {
core_slice::SliceExt::chunks(self, size)
}
#[inline]
fn get<'a>(&'a self, index: uint) -> Option<&'a T> {
core_slice::SliceExt::get(self, index)
}
#[inline]
fn head<'a>(&'a self) -> Option<&'a T> {
core_slice::SliceExt::head(self)
}
#[inline]
fn tail<'a>(&'a self) -> &'a [T] {
core_slice::SliceExt::tail(self)
}
#[inline]
fn init<'a>(&'a self) -> &'a [T] {
core_slice::SliceExt::init(self)
}
#[inline]
fn last<'a>(&'a self) -> Option<&'a T> {
core_slice::SliceExt::last(self)
}
#[inline]
unsafe fn unsafe_get<'a>(&'a self, index: uint) -> &'a T {
core_slice::SliceExt::unsafe_get(self, index)
}
#[inline]
fn as_ptr(&self) -> *const T {
core_slice::SliceExt::as_ptr(self)
}
#[inline]
fn binary_search<F>(&self, f: F) -> BinarySearchResult
where F: FnMut(&T) -> Ordering {
core_slice::SliceExt::binary_search(self, f)
}
#[inline]
fn len(&self) -> uint {
core_slice::SliceExt::len(self)
}
#[inline]
fn is_empty(&self) -> bool {
core_slice::SliceExt::is_empty(self)
}
#[inline]
fn get_mut<'a>(&'a mut self, index: uint) -> Option<&'a mut T> {
core_slice::SliceExt::get_mut(self, index)
}
#[inline]
fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] {
core_slice::SliceExt::as_mut_slice(self)
}
#[inline]
fn slice_mut<'a>(&'a mut self, start: uint, end: uint) -> &'a mut [T] {
core_slice::SliceExt::slice_mut(self, start, end)
}
#[inline]
fn slice_from_mut<'a>(&'a mut self, start: uint) -> &'a mut [T] {
core_slice::SliceExt::slice_from_mut(self, start)
}
#[inline]
fn slice_to_mut<'a>(&'a mut self, end: uint) -> &'a mut [T] {
core_slice::SliceExt::slice_to_mut(self, end)
}
#[inline]
fn iter_mut<'a>(&'a mut self) -> MutItems<'a, T> {
core_slice::SliceExt::iter_mut(self)
}
#[inline]
fn head_mut<'a>(&'a mut self) -> Option<&'a mut T> {
core_slice::SliceExt::head_mut(self)
}
#[inline]
fn tail_mut<'a>(&'a mut self) -> &'a mut [T] {
core_slice::SliceExt::tail_mut(self)
}
#[inline]
fn init_mut<'a>(&'a mut self) -> &'a mut [T] {
core_slice::SliceExt::init_mut(self)
}
#[inline]
fn last_mut<'a>(&'a mut self) -> Option<&'a mut T> {
core_slice::SliceExt::last_mut(self)
}
#[inline]
fn split_mut<F>(&mut self, pred: F) -> MutSplits<T, F>
where F: FnMut(&T) -> bool {
core_slice::SliceExt::split_mut(self, pred)
}
#[inline]
fn splitn_mut<F>(&mut self, n: uint, pred: F) -> SplitsN<MutSplits<T, F>>
where F: FnMut(&T) -> bool {
core_slice::SliceExt::splitn_mut(self, n, pred)
}
#[inline]
fn rsplitn_mut<F>(&mut self, n: uint, pred: F) -> SplitsN<MutSplits<T, F>>
where F: FnMut(&T) -> bool {
core_slice::SliceExt::rsplitn_mut(self, n, pred)
}
#[inline]
fn chunks_mut<'a>(&'a mut self, chunk_size: uint) -> MutChunks<'a, T> {
core_slice::SliceExt::chunks_mut(self, chunk_size)
}
#[inline]
fn swap(&mut self, a: uint, b: uint) {
core_slice::SliceExt::swap(self, a, b)
}
#[inline]
fn split_at_mut<'a>(&'a mut self, mid: uint) -> (&'a mut [T], &'a mut [T]) {
core_slice::SliceExt::split_at_mut(self, mid)
}
#[inline]
fn reverse(&mut self) {
core_slice::SliceExt::reverse(self)
}
#[inline]
unsafe fn unsafe_mut<'a>(&'a mut self, index: uint) -> &'a mut T {
core_slice::SliceExt::unsafe_mut(self, index)
}
#[inline]
fn as_mut_ptr(&mut self) -> *mut T {
core_slice::SliceExt::as_mut_ptr(self)
}
}
#[unstable = "trait is unstable"]

View File

@ -51,19 +51,17 @@
#![doc(primitive = "str")]
use core::prelude::*;
pub use self::MaybeOwned::*;
use self::RecompositionState::*;
use self::DecompositionType::*;
use core::borrow::{BorrowFrom, Cow, ToOwned};
use core::default::Default;
use core::fmt;
use core::cmp;
use core::iter::AdditiveIterator;
use core::kinds::Sized;
use core::prelude::{Char, Clone, Eq, Equiv};
use core::prelude::{Iterator, IteratorExt, SlicePrelude, None, Option, Ord, Ordering};
use core::prelude::{PartialEq, PartialOrd, Result, AsSlice, Some};
use core::prelude::{range};
use hash;
use ring_buf::RingBuf;
@ -849,10 +847,10 @@ mod tests {
use std::iter::{Iterator, IteratorExt, DoubleEndedIteratorExt};
use super::*;
use std::slice::{AsSlice, SlicePrelude};
use std::slice::{AsSlice, SliceExt};
use string::String;
use vec::Vec;
use slice::CloneSliceAllocPrelude;
use slice::CloneSliceExt;
use unicode::char::UnicodeChar;
@ -2464,7 +2462,7 @@ mod bench {
use super::*;
use std::iter::{IteratorExt, DoubleEndedIteratorExt};
use std::str::StrPrelude;
use std::slice::SlicePrelude;
use std::slice::SliceExt;
#[bench]
fn char_iterator(b: &mut Bencher) {

View File

@ -24,7 +24,7 @@ use core::ops;
use core::raw::Slice as RawSlice;
use hash;
use slice::CloneSliceAllocPrelude;
use slice::CloneSliceExt;
use str;
use str::{CharRange, CowString, FromStr, StrAllocating, Owned};
use vec::{DerefVec, Vec, as_vec};
@ -1032,7 +1032,7 @@ mod tests {
use std::prelude::*;
use test::Bencher;
use slice::CloneSliceAllocPrelude;
use slice::CloneSliceExt;
use str::{Str, StrPrelude};
use str;
use super::{as_string, String, ToString};

View File

@ -29,7 +29,7 @@ use core::ptr;
use core::raw::Slice as RawSlice;
use core::uint;
use slice::{CloneSliceAllocPrelude};
use slice::CloneSliceExt;
/// An owned, growable vector.
///

View File

@ -20,7 +20,7 @@ use ops::FnMut;
use option::Option;
use option::Option::{None, Some};
use iter::{range_step, Iterator, RangeStep};
use slice::SlicePrelude;
use slice::SliceExt;
// UTF-8 ranges and tags for encoding characters
static TAG_CONT: u8 = 0b1000_0000u8;

View File

@ -22,7 +22,7 @@ use num::{Float, FPNaN, FPInfinite, ToPrimitive};
use num::cast;
use ops::FnOnce;
use result::Result::Ok;
use slice::{mod, SlicePrelude};
use slice::{mod, SliceExt};
use str::StrPrelude;
/// A flag that specifies whether to use exponential (scientific) notation.

View File

@ -22,7 +22,7 @@ use option::Option::{Some, None};
use ops::{Deref, FnOnce};
use result::Result::{Ok, Err};
use result;
use slice::SlicePrelude;
use slice::SliceExt;
use slice;
use str::StrPrelude;

View File

@ -18,7 +18,7 @@ use fmt;
use iter::DoubleEndedIteratorExt;
use kinds::Copy;
use num::{Int, cast};
use slice::SlicePrelude;
use slice::SliceExt;
/// A type that represents a specific radix
#[doc(hidden)]

View File

@ -64,5 +64,5 @@ pub use str::{Str, StrPrelude};
pub use tuple::{Tuple1, Tuple2, Tuple3, Tuple4};
pub use tuple::{Tuple5, Tuple6, Tuple7, Tuple8};
pub use tuple::{Tuple9, Tuple10, Tuple11, Tuple12};
pub use slice::{PartialEqSlicePrelude, OrdSlicePrelude};
pub use slice::{AsSlice, SlicePrelude};
pub use slice::{PartialEqSliceExt, OrdSliceExt};
pub use slice::{AsSlice, SliceExt};

View File

@ -61,377 +61,58 @@ use raw::Slice as RawSlice;
//
/// Extension methods for slices.
#[unstable = "may merge with other traits"]
pub trait SlicePrelude<T> for Sized? {
/// Returns a subslice spanning the interval [`start`, `end`).
///
/// Panics when the end of the new slice lies beyond the end of the
/// original slice (i.e. when `end > self.len()`) or when `start > end`.
///
/// Slicing with `start` equal to `end` yields an empty slice.
#[unstable = "waiting on final error conventions/slicing syntax"]
#[allow(missing_docs)] // docs in libcollections
pub trait SliceExt<T> for Sized? {
fn slice<'a>(&'a self, start: uint, end: uint) -> &'a [T];
/// Returns a subslice from `start` to the end of the slice.
///
/// Panics when `start` is strictly greater than the length of the original slice.
///
/// Slicing from `self.len()` yields an empty slice.
#[unstable = "waiting on final error conventions/slicing syntax"]
fn slice_from<'a>(&'a self, start: uint) -> &'a [T];
/// Returns a subslice from the start of the slice to `end`.
///
/// Panics when `end` is strictly greater than the length of the original slice.
///
/// Slicing to `0` yields an empty slice.
#[unstable = "waiting on final error conventions/slicing syntax"]
fn slice_to<'a>(&'a self, end: uint) -> &'a [T];
/// Divides one slice into two at an index.
///
/// The first will contain all indices from `[0, mid)` (excluding
/// the index `mid` itself) and the second will contain all
/// indices from `[mid, len)` (excluding the index `len` itself).
///
/// Panics if `mid > len`.
#[unstable = "waiting on final error conventions"]
fn split_at<'a>(&'a self, mid: uint) -> (&'a [T], &'a [T]);
/// Returns an iterator over the slice
#[unstable = "iterator type may change"]
fn iter<'a>(&'a self) -> Items<'a, T>;
/// Returns an iterator over subslices separated by elements that match
/// `pred`. The matched element is not contained in the subslices.
#[unstable = "iterator type may change, waiting on unboxed closures"]
fn split<'a, P>(&'a self, pred: P) -> Splits<'a, T, P> where
P: FnMut(&T) -> bool;
/// Returns an iterator over subslices separated by elements that match
/// `pred`, limited to splitting at most `n` times. The matched element is
/// not contained in the subslices.
#[unstable = "iterator type may change"]
fn splitn<'a, P>(&'a self, n: uint, pred: P) -> SplitsN<Splits<'a, T, P>> where
P: FnMut(&T) -> bool;
/// Returns an iterator over subslices separated by elements that match
/// `pred` limited to splitting at most `n` times. This starts at the end of
/// the slice and works backwards. The matched element is not contained in
/// the subslices.
#[unstable = "iterator type may change"]
fn rsplitn<'a, P>(&'a self, n: uint, pred: P) -> SplitsN<Splits<'a, T, P>> where
P: FnMut(&T) -> bool;
/// Returns an iterator over all contiguous windows of length
/// `size`. The windows overlap. If the slice is shorter than
/// `size`, the iterator returns no values.
///
/// # Panics
///
/// Panics if `size` is 0.
///
/// # Example
///
/// Print the adjacent pairs of a slice (i.e. `[1,2]`, `[2,3]`,
/// `[3,4]`):
///
/// ```rust
/// let v = &[1i, 2, 3, 4];
/// for win in v.windows(2) {
/// println!("{}", win);
/// }
/// ```
#[unstable = "iterator type may change"]
fn split<'a, P>(&'a self, pred: P) -> Splits<'a, T, P>
where P: FnMut(&T) -> bool;
fn splitn<'a, P>(&'a self, n: uint, pred: P) -> SplitsN<Splits<'a, T, P>>
where P: FnMut(&T) -> bool;
fn rsplitn<'a, P>(&'a self, n: uint, pred: P) -> SplitsN<Splits<'a, T, P>>
where P: FnMut(&T) -> bool;
fn windows<'a>(&'a self, size: uint) -> Windows<'a, T>;
/// Returns an iterator over `size` elements of the slice at a
/// time. The chunks do not overlap. If `size` does not divide the
/// length of the slice, then the last chunk will not have length
/// `size`.
///
/// # Panics
///
/// Panics if `size` is 0.
///
/// # Example
///
/// Print the slice two elements at a time (i.e. `[1,2]`,
/// `[3,4]`, `[5]`):
///
/// ```rust
/// let v = &[1i, 2, 3, 4, 5];
/// for win in v.chunks(2) {
/// println!("{}", win);
/// }
/// ```
#[unstable = "iterator type may change"]
fn chunks<'a>(&'a self, size: uint) -> Chunks<'a, T>;
/// Returns the element of a slice at the given index, or `None` if the
/// index is out of bounds.
#[unstable = "waiting on final collection conventions"]
fn get<'a>(&'a self, index: uint) -> Option<&'a T>;
/// Returns the first element of a slice, or `None` if it is empty.
#[unstable = "name may change"]
fn head<'a>(&'a self) -> Option<&'a T>;
/// Returns all but the first element of a slice.
#[unstable = "name may change"]
fn tail<'a>(&'a self) -> &'a [T];
/// Returns all but the last element of a slice.
#[unstable = "name may change"]
fn init<'a>(&'a self) -> &'a [T];
/// Returns the last element of a slice, or `None` if it is empty.
#[unstable = "name may change"]
fn last<'a>(&'a self) -> Option<&'a T>;
/// Returns a pointer to the element at the given index, without doing
/// bounds checking.
#[unstable]
unsafe fn unsafe_get<'a>(&'a self, index: uint) -> &'a T;
/// Returns an unsafe pointer to the slice's buffer
///
/// The caller must ensure that the slice outlives the pointer this
/// function returns, or else it will end up pointing to garbage.
///
/// Modifying the slice may cause its buffer to be reallocated, which
/// would also make any pointers to it invalid.
#[unstable]
fn as_ptr(&self) -> *const T;
/// Binary search a sorted slice with a comparator function.
///
/// The comparator function should implement an order consistent
/// with the sort order of the underlying slice, returning an
/// order code that indicates whether its argument is `Less`,
/// `Equal` or `Greater` the desired target.
///
/// If a matching value is found then returns `Found`, containing
/// the index for the matched element; if no match is found then
/// `NotFound` is returned, containing the index where a matching
/// element could be inserted while maintaining sorted order.
///
/// # Example
///
/// Looks up a series of four elements. The first is found, with a
/// uniquely determined position; the second and third are not
/// found; the fourth could match any position in `[1,4]`.
///
/// ```rust
/// use std::slice::BinarySearchResult::{Found, NotFound};
/// let s = [0i, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
/// let s = s.as_slice();
///
/// let seek = 13;
/// assert_eq!(s.binary_search(|probe| probe.cmp(&seek)), Found(9));
/// let seek = 4;
/// assert_eq!(s.binary_search(|probe| probe.cmp(&seek)), NotFound(7));
/// let seek = 100;
/// assert_eq!(s.binary_search(|probe| probe.cmp(&seek)), NotFound(13));
/// let seek = 1;
/// let r = s.binary_search(|probe| probe.cmp(&seek));
/// assert!(match r { Found(1...4) => true, _ => false, });
/// ```
#[unstable = "waiting on unboxed closures"]
fn binary_search<F>(&self, f: F) -> BinarySearchResult where F: FnMut(&T) -> Ordering;
/// Return the number of elements in the slice
///
/// # Example
///
/// ```
/// let a = [1i, 2, 3];
/// assert_eq!(a.len(), 3);
/// ```
#[experimental = "not triaged yet"]
fn binary_search<F>(&self, f: F) -> BinarySearchResult
where F: FnMut(&T) -> Ordering;
fn len(&self) -> uint;
/// Returns true if the slice has a length of 0
///
/// # Example
///
/// ```
/// let a = [1i, 2, 3];
/// assert!(!a.is_empty());
/// ```
#[inline]
#[experimental = "not triaged yet"]
fn is_empty(&self) -> bool { self.len() == 0 }
/// Returns a mutable reference to the element at the given index,
/// or `None` if the index is out of bounds
#[unstable = "waiting on final error conventions"]
fn get_mut<'a>(&'a mut self, index: uint) -> Option<&'a mut T>;
/// Work with `self` as a mut slice.
/// Primarily intended for getting a &mut [T] from a [T, ..N].
fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T];
/// Returns a mutable subslice spanning the interval [`start`, `end`).
///
/// Panics when the end of the new slice lies beyond the end of the
/// original slice (i.e. when `end > self.len()`) or when `start > end`.
///
/// Slicing with `start` equal to `end` yields an empty slice.
#[unstable = "waiting on final error conventions"]
fn slice_mut<'a>(&'a mut self, start: uint, end: uint) -> &'a mut [T];
/// Returns a mutable subslice from `start` to the end of the slice.
///
/// Panics when `start` is strictly greater than the length of the original slice.
///
/// Slicing from `self.len()` yields an empty slice.
#[unstable = "waiting on final error conventions"]
fn slice_from_mut<'a>(&'a mut self, start: uint) -> &'a mut [T];
/// Returns a mutable subslice from the start of the slice to `end`.
///
/// Panics when `end` is strictly greater than the length of the original slice.
///
/// Slicing to `0` yields an empty slice.
#[unstable = "waiting on final error conventions"]
fn slice_to_mut<'a>(&'a mut self, end: uint) -> &'a mut [T];
/// Returns an iterator that allows modifying each value
#[unstable = "waiting on iterator type name conventions"]
fn iter_mut<'a>(&'a mut self) -> MutItems<'a, T>;
/// Returns a mutable pointer to the first element of a slice, or `None` if it is empty
#[unstable = "name may change"]
fn head_mut<'a>(&'a mut self) -> Option<&'a mut T>;
/// Returns all but the first element of a mutable slice
#[unstable = "name may change"]
fn tail_mut<'a>(&'a mut self) -> &'a mut [T];
/// Returns all but the last element of a mutable slice
#[unstable = "name may change"]
fn init_mut<'a>(&'a mut self) -> &'a mut [T];
/// Returns a mutable pointer to the last item in the slice.
#[unstable = "name may change"]
fn last_mut<'a>(&'a mut self) -> Option<&'a mut T>;
/// Returns an iterator over mutable subslices separated by elements that
/// match `pred`. The matched element is not contained in the subslices.
#[unstable = "waiting on unboxed closures, iterator type name conventions"]
fn split_mut<'a, P>(&'a mut self, pred: P) -> MutSplits<'a, T, P> where
P: FnMut(&T) -> bool;
/// Returns an iterator over subslices separated by elements that match
/// `pred`, limited to splitting at most `n` times. The matched element is
/// not contained in the subslices.
#[unstable = "waiting on unboxed closures, iterator type name conventions"]
fn splitn_mut<'a, P>(&'a mut self, n: uint, pred: P) -> SplitsN<MutSplits<'a, T, P>> where
P: FnMut(&T) -> bool;
/// Returns an iterator over subslices separated by elements that match
/// `pred` limited to splitting at most `n` times. This starts at the end of
/// the slice and works backwards. The matched element is not contained in
/// the subslices.
#[unstable = "waiting on unboxed closures, iterator type name conventions"]
fn rsplitn_mut<'a, P>(&'a mut self, n: uint, pred: P) -> SplitsN<MutSplits<'a, T, P>> where
P: FnMut(&T) -> bool;
/// Returns an iterator over `chunk_size` elements of the slice at a time.
/// The chunks are mutable and do not overlap. If `chunk_size` does
/// not divide the length of the slice, then the last chunk will not
/// have length `chunk_size`.
///
/// # Panics
///
/// Panics if `chunk_size` is 0.
#[unstable = "waiting on iterator type name conventions"]
fn split_mut<'a, P>(&'a mut self, pred: P) -> MutSplits<'a, T, P>
where P: FnMut(&T) -> bool;
fn splitn_mut<P>(&mut self, n: uint, pred: P) -> SplitsN<MutSplits<T, P>>
where P: FnMut(&T) -> bool;
fn rsplitn_mut<P>(&mut self, n: uint, pred: P) -> SplitsN<MutSplits<T, P>>
where P: FnMut(&T) -> bool;
fn chunks_mut<'a>(&'a mut self, chunk_size: uint) -> MutChunks<'a, T>;
/// Swaps two elements in a slice.
///
/// Panics if `a` or `b` are out of bounds.
///
/// # Arguments
///
/// * a - The index of the first element
/// * b - The index of the second element
///
/// # Example
///
/// ```rust
/// let mut v = ["a", "b", "c", "d"];
/// v.swap(1, 3);
/// assert!(v == ["a", "d", "c", "b"]);
/// ```
#[unstable = "waiting on final error conventions"]
fn swap(&mut self, a: uint, b: uint);
/// Divides one `&mut` into two at an index.
///
/// The first will contain all indices from `[0, mid)` (excluding
/// the index `mid` itself) and the second will contain all
/// indices from `[mid, len)` (excluding the index `len` itself).
///
/// Panics if `mid > len`.
///
/// # Example
///
/// ```rust
/// let mut v = [1i, 2, 3, 4, 5, 6];
///
/// // scoped to restrict the lifetime of the borrows
/// {
/// let (left, right) = v.split_at_mut(0);
/// assert!(left == []);
/// assert!(right == [1i, 2, 3, 4, 5, 6]);
/// }
///
/// {
/// let (left, right) = v.split_at_mut(2);
/// assert!(left == [1i, 2]);
/// assert!(right == [3i, 4, 5, 6]);
/// }
///
/// {
/// let (left, right) = v.split_at_mut(6);
/// assert!(left == [1i, 2, 3, 4, 5, 6]);
/// assert!(right == []);
/// }
/// ```
#[unstable = "waiting on final error conventions"]
fn split_at_mut<'a>(&'a mut self, mid: uint) -> (&'a mut [T], &'a mut [T]);
/// Reverse the order of elements in a slice, in place.
///
/// # Example
///
/// ```rust
/// let mut v = [1i, 2, 3];
/// v.reverse();
/// assert!(v == [3i, 2, 1]);
/// ```
#[experimental = "may be moved to iterators instead"]
fn reverse(&mut self);
/// Returns an unsafe mutable pointer to the element in index
#[experimental = "waiting on unsafe conventions"]
unsafe fn unsafe_mut<'a>(&'a mut self, index: uint) -> &'a mut T;
/// Return an unsafe mutable pointer to the slice's buffer.
///
/// The caller must ensure that the slice outlives the pointer this
/// function returns, or else it will end up pointing to garbage.
///
/// Modifying the slice may cause its buffer to be reallocated, which
/// would also make any pointers to it invalid.
#[inline]
#[unstable]
fn as_mut_ptr(&mut self) -> *mut T;
}
#[unstable]
impl<T> SlicePrelude<T> for [T] {
impl<T> SliceExt<T> for [T] {
#[inline]
fn slice(&self, start: uint, end: uint) -> &[T] {
assert!(start <= end);
@ -789,7 +470,7 @@ impl<T> ops::SliceMut<uint, [T]> for [T] {
/// Extension methods for slices containing `PartialEq` elements.
#[unstable = "may merge with other traits"]
pub trait PartialEqSlicePrelude<T: PartialEq> for Sized? {
pub trait PartialEqSliceExt<T: PartialEq> for Sized? {
/// Find the first index containing a matching value.
fn position_elem(&self, t: &T) -> Option<uint>;
@ -807,7 +488,7 @@ pub trait PartialEqSlicePrelude<T: PartialEq> for Sized? {
}
#[unstable = "trait is unstable"]
impl<T: PartialEq> PartialEqSlicePrelude<T> for [T] {
impl<T: PartialEq> PartialEqSliceExt<T> for [T] {
#[inline]
fn position_elem(&self, x: &T) -> Option<uint> {
self.iter().position(|y| *x == *y)
@ -838,75 +519,18 @@ impl<T: PartialEq> PartialEqSlicePrelude<T> for [T] {
/// Extension methods for slices containing `Ord` elements.
#[unstable = "may merge with other traits"]
pub trait OrdSlicePrelude<T: Ord> for Sized? {
/// Binary search a sorted slice for a given element.
///
/// If the value is found then `Found` is returned, containing the
/// index of the matching element; if the value is not found then
/// `NotFound` is returned, containing the index where a matching
/// element could be inserted while maintaining sorted order.
///
/// # Example
///
/// Looks up a series of four elements. The first is found, with a
/// uniquely determined position; the second and third are not
/// found; the fourth could match any position in `[1,4]`.
///
/// ```rust
/// use std::slice::BinarySearchResult::{Found, NotFound};
/// let s = [0i, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
/// let s = s.as_slice();
///
/// assert_eq!(s.binary_search_elem(&13), Found(9));
/// assert_eq!(s.binary_search_elem(&4), NotFound(7));
/// assert_eq!(s.binary_search_elem(&100), NotFound(13));
/// let r = s.binary_search_elem(&1);
/// assert!(match r { Found(1...4) => true, _ => false, });
/// ```
#[allow(missing_docs)] // docs in libcollections
pub trait OrdSliceExt<T: Ord> for Sized? {
#[unstable = "name likely to change"]
fn binary_search_elem(&self, x: &T) -> BinarySearchResult;
/// Mutates the slice to the next lexicographic permutation.
///
/// Returns `true` if successful and `false` if the slice is at the
/// last-ordered permutation.
///
/// # Example
///
/// ```rust
/// let v: &mut [_] = &mut [0i, 1, 2];
/// v.next_permutation();
/// let b: &mut [_] = &mut [0i, 2, 1];
/// assert!(v == b);
/// v.next_permutation();
/// let b: &mut [_] = &mut [1i, 0, 2];
/// assert!(v == b);
/// ```
#[experimental]
fn next_permutation(&mut self) -> bool;
/// Mutates the slice to the previous lexicographic permutation.
///
/// Returns `true` if successful and `false` if the slice is at the
/// first-ordered permutation.
///
/// # Example
///
/// ```rust
/// let v: &mut [_] = &mut [1i, 0, 2];
/// v.prev_permutation();
/// let b: &mut [_] = &mut [0i, 2, 1];
/// assert!(v == b);
/// v.prev_permutation();
/// let b: &mut [_] = &mut [0i, 1, 2];
/// assert!(v == b);
/// ```
#[experimental]
fn prev_permutation(&mut self) -> bool;
}
#[unstable = "trait is unstable"]
impl<T: Ord> OrdSlicePrelude<T> for [T] {
impl<T: Ord> OrdSliceExt<T> for [T] {
#[unstable]
fn binary_search_elem(&self, x: &T) -> BinarySearchResult {
self.binary_search(|p| p.cmp(x))
@ -977,31 +601,13 @@ impl<T: Ord> OrdSlicePrelude<T> for [T] {
/// Extension methods for slices on Clone elements
#[unstable = "may merge with other traits"]
pub trait CloneSlicePrelude<T> for Sized? {
/// Copies as many elements from `src` as it can into `self` (the
/// shorter of `self.len()` and `src.len()`). Returns the number
/// of elements copied.
///
/// # Example
///
/// ```rust
/// use std::slice::CloneSlicePrelude;
///
/// let mut dst = [0i, 0, 0];
/// let src = [1i, 2];
///
/// assert!(dst.clone_from_slice(&src) == 2);
/// assert!(dst == [1, 2, 0]);
///
/// let src2 = [3i, 4, 5, 6];
/// assert!(dst.clone_from_slice(&src2) == 3);
/// assert!(dst == [3i, 4, 5]);
/// ```
#[allow(missing_docs)] // docs in libcollections
pub trait CloneSliceExt<T> for Sized? {
fn clone_from_slice(&mut self, &[T]) -> uint;
}
#[unstable = "trait is unstable"]
impl<T: Clone> CloneSlicePrelude<T> for [T] {
impl<T: Clone> CloneSliceExt<T> for [T] {
#[inline]
fn clone_from_slice(&mut self, src: &[T]) -> uint {
let min = cmp::min(self.len(), src.len());
@ -1014,9 +620,6 @@ impl<T: Clone> CloneSlicePrelude<T> for [T] {
}
}
//
// Common traits
//
@ -1786,7 +1389,7 @@ pub mod raw {
pub mod bytes {
use kinds::Sized;
use ptr;
use slice::SlicePrelude;
use slice::SliceExt;
/// A trait for operations on mutable `[u8]`s.
pub trait MutableByteVector for Sized? {

View File

@ -34,7 +34,7 @@ use option::Option::{None, Some};
use ops::FnMut;
use ptr::RawPtr;
use raw::{Repr, Slice};
use slice::{mod, SlicePrelude};
use slice::{mod, SliceExt};
use uint;
/// A trait to abstract the idea of creating a new instance of a type from a
@ -1146,7 +1146,7 @@ const TAG_CONT_U8: u8 = 0b1000_0000u8;
pub mod raw {
use ptr::RawPtr;
use raw::Slice;
use slice::SlicePrelude;
use slice::SliceExt;
use str::{is_utf8, StrPrelude};
/// Converts a slice of bytes to a string slice without checking

View File

@ -16,7 +16,7 @@ use std::default::Default;
use std::fmt;
use std::iter::FromIterator;
use std::path::BytesContainer;
use std::slice::{mod, Permutations};
use std::slice;
// Note 1: It is not clear whether the flexibility of providing both
// the `Growable` and `FixedLen` variants is sufficiently useful.
@ -136,21 +136,6 @@ impl<'a,T:fmt::Show> fmt::Show for MaybeOwnedVector<'a,T> {
}
}
impl<'a,T:Clone> CloneSliceAllocPrelude<T> for MaybeOwnedVector<'a,T> {
/// Returns a copy of `self`.
fn to_vec(&self) -> Vec<T> {
self.as_slice().to_vec()
}
fn partitioned<F>(&self, f: F) -> (Vec<T>, Vec<T>) where F: FnMut(&T) -> bool {
self.as_slice().partitioned(f)
}
fn permutations(&self) -> Permutations<T> {
self.as_slice().permutations()
}
}
impl<'a, T: Clone> Clone for MaybeOwnedVector<'a, T> {
#[allow(deprecated)]
fn clone(&self) -> MaybeOwnedVector<'a, T> {

View File

@ -38,7 +38,7 @@ pub use self::StepState::*;
use std::cmp;
use std::mem;
use std::slice::SlicePrelude;
use std::slice::SliceExt;
use compile::{
Program,
Match, OneChar, CharClass, Any, EmptyBegin, EmptyEnd, EmptyWordBoundary,

View File

@ -67,15 +67,13 @@
//! }
//! ```
use core::prelude::*;
use collections::string::String;
use collections::hash;
use core::fmt;
use core::kinds::{Sized, marker};
use core::mem;
use core::ops::{FnMut, FnOnce};
use core::prelude::{Clone, Drop, Eq, Iterator};
use core::prelude::{SlicePrelude, None, Option, Ordering, PartialEq};
use core::prelude::{PartialOrd, RawPtr, Some, StrPrelude, range};
use core::ptr;
use core::raw::Slice;
use core::slice;

View File

@ -23,7 +23,7 @@ use mem;
use ops::FnMut;
use option::Option;
use option::Option::{Some, None};
use slice::{SlicePrelude, AsSlice};
use slice::{SliceExt, AsSlice};
use str::{Str, StrPrelude};
use string::{String, IntoString};
use vec::Vec;

View File

@ -638,7 +638,7 @@ mod test_set {
use prelude::*;
use super::HashSet;
use slice::PartialEqSlicePrelude;
use slice::PartialEqSliceExt;
#[test]
fn test_disjoint() {

View File

@ -26,7 +26,7 @@ use os;
use path::{Path,GenericPath};
use result::*;
use result::Result::{Err, Ok};
use slice::{AsSlice,SlicePrelude};
use slice::{AsSlice,SliceExt};
use str;
use string::String;
use vec::Vec;
@ -295,7 +295,7 @@ pub mod dl {
use ptr;
use result::Result;
use result::Result::{Ok, Err};
use slice::SlicePrelude;
use slice::SliceExt;
use str::StrPrelude;
use str;
use string::String;

View File

@ -19,7 +19,7 @@ use ops::Drop;
use option::Option;
use option::Option::{Some, None};
use result::Result::{Ok, Err};
use slice::{SlicePrelude};
use slice::{SliceExt};
use slice;
use vec::Vec;

View File

@ -14,7 +14,7 @@ use comm::{Sender, Receiver};
use io;
use option::Option::{None, Some};
use result::Result::{Ok, Err};
use slice::{bytes, CloneSliceAllocPrelude, SlicePrelude};
use slice::{bytes, CloneSliceExt, SliceExt};
use super::{Buffer, Reader, Writer, IoResult};
use vec::Vec;

View File

@ -24,7 +24,7 @@ use option::Option;
use option::Option::{Some, None};
use ptr::RawPtr;
use result::Result::{Ok, Err};
use slice::{SlicePrelude, AsSlice};
use slice::{SliceExt, AsSlice};
/// An iterator that reads a single byte on each iteration,
/// until `.read_byte()` returns `EndOfFile`.
@ -156,7 +156,7 @@ pub fn u64_to_be_bytes<T, F>(n: u64, size: uint, f: F) -> T where
/// 32-bit value is parsed.
pub fn u64_from_be_bytes(data: &[u8], start: uint, size: uint) -> u64 {
use ptr::{copy_nonoverlapping_memory};
use slice::SlicePrelude;
use slice::SliceExt;
assert!(size <= 8u);

View File

@ -64,7 +64,7 @@ use option::Option::{Some, None};
use path::{Path, GenericPath};
use path;
use result::Result::{Err, Ok};
use slice::SlicePrelude;
use slice::SliceExt;
use string::String;
use vec::Vec;

View File

@ -19,7 +19,7 @@ use option::Option::None;
use result::Result::{Err, Ok};
use io;
use io::{Reader, Writer, Seek, Buffer, IoError, SeekStyle, IoResult};
use slice::{mod, AsSlice, SlicePrelude};
use slice::{mod, AsSlice, SliceExt};
use vec::Vec;
const BUF_CAPACITY: uint = 128;

View File

@ -241,7 +241,7 @@ use boxed::Box;
use result::Result;
use result::Result::{Ok, Err};
use sys;
use slice::SlicePrelude;
use slice::SliceExt;
use str::StrPrelude;
use str;
use string::String;

View File

@ -27,7 +27,7 @@ use option::Option;
use option::Option::{None, Some};
use result::Result::{Ok, Err};
use str::{FromStr, StrPrelude};
use slice::{CloneSlicePrelude, SlicePrelude};
use slice::{CloneSliceExt, SliceExt};
use vec::Vec;
pub type Port = u16;

View File

@ -44,7 +44,7 @@ use result::Result::{Ok, Err};
use rustrt;
use rustrt::local::Local;
use rustrt::task::Task;
use slice::SlicePrelude;
use slice::SliceExt;
use str::StrPrelude;
use string::String;
use sys::{fs, tty};

View File

@ -337,7 +337,7 @@ macro_rules! try (
#[macro_export]
macro_rules! vec[
($($x:expr),*) => ({
use std::slice::BoxedSlicePrelude;
use std::slice::BoxedSliceExt;
let xs: ::std::boxed::Box<[_]> = box [$($x),*];
xs.into_vec()
});

View File

@ -16,13 +16,11 @@ pub use self::ExponentFormat::*;
pub use self::SignificantDigits::*;
pub use self::SignFormat::*;
use char;
use char::Char;
use char::{mod, Char};
use kinds::Copy;
use num;
use num::{Int, Float, FPNaN, FPInfinite, ToPrimitive};
use num::{mod, Int, Float, FPNaN, FPInfinite, ToPrimitive};
use ops::FnMut;
use slice::{SlicePrelude, CloneSliceAllocPrelude};
use slice::{SliceExt, CloneSliceExt};
use str::StrPrelude;
use string::String;
use vec::Vec;

View File

@ -51,8 +51,8 @@ use ptr::RawPtr;
use ptr;
use result::Result;
use result::Result::{Err, Ok};
use slice::{AsSlice, SlicePrelude, PartialEqSlicePrelude};
use slice::CloneSliceAllocPrelude;
use slice::{AsSlice, SliceExt, PartialEqSliceExt};
use slice::CloneSliceExt;
use str::{Str, StrPrelude, StrAllocating};
use string::{String, ToString};
use sync::atomic::{AtomicInt, INIT_ATOMIC_INT, SeqCst};
@ -168,7 +168,7 @@ pub mod windoze {
use option::Option::None;
use option;
use os::TMPBUF_SZ;
use slice::{SlicePrelude};
use slice::SliceExt;
use string::String;
use str::StrPrelude;
use vec::Vec;

View File

@ -71,8 +71,8 @@ use option::Option::{None, Some};
use str;
use str::{CowString, MaybeOwned, Str, StrPrelude};
use string::String;
use slice::{AsSlice, CloneSliceAllocPrelude};
use slice::{PartialEqSlicePrelude, SlicePrelude};
use slice::{AsSlice, CloneSliceExt};
use slice::{PartialEqSliceExt, SliceExt};
use vec::Vec;
/// Typedef for POSIX file paths.

View File

@ -22,8 +22,8 @@ use option::Option::{None, Some};
use kinds::Sized;
use str::{FromStr, Str};
use str;
use slice::{CloneSliceAllocPrelude, Splits, AsSlice, VectorVector,
PartialEqSlicePrelude, SlicePrelude};
use slice::{CloneSliceExt, Splits, AsSlice, VectorVector,
PartialEqSliceExt, SliceExt};
use vec::Vec;
use super::{BytesContainer, GenericPath, GenericPathUnsafe};

View File

@ -26,7 +26,7 @@ use kinds::Copy;
use mem;
use option::Option;
use option::Option::{Some, None};
use slice::{AsSlice, SlicePrelude};
use slice::{AsSlice, SliceExt};
use str::{CharSplits, FromStr, Str, StrAllocating, StrVector, StrPrelude};
use string::String;
use unicode::char::UnicodeChar;

View File

@ -84,10 +84,10 @@
#[doc(no_inline)] pub use tuple::{Tuple1, Tuple2, Tuple3, Tuple4};
#[doc(no_inline)] pub use tuple::{Tuple5, Tuple6, Tuple7, Tuple8};
#[doc(no_inline)] pub use tuple::{Tuple9, Tuple10, Tuple11, Tuple12};
#[doc(no_inline)] pub use slice::{SlicePrelude, AsSlice, CloneSlicePrelude};
#[doc(no_inline)] pub use slice::{VectorVector, PartialEqSlicePrelude, OrdSlicePrelude};
#[doc(no_inline)] pub use slice::{CloneSliceAllocPrelude, OrdSliceAllocPrelude, SliceAllocPrelude};
#[doc(no_inline)] pub use slice::{BoxedSlicePrelude};
#[doc(no_inline)] pub use slice::AsSlice;
#[doc(no_inline)] pub use slice::{VectorVector, PartialEqSliceExt};
#[doc(no_inline)] pub use slice::{CloneSliceExt, OrdSliceExt, SliceExt};
#[doc(no_inline)] pub use slice::{BoxedSliceExt};
#[doc(no_inline)] pub use string::{IntoString, String, ToString};
#[doc(no_inline)] pub use vec::Vec;

View File

@ -24,7 +24,7 @@ mod imp {
use rand::Rng;
use rand::reader::ReaderRng;
use result::Result::{Ok, Err};
use slice::SlicePrelude;
use slice::SliceExt;
use mem;
use os::errno;
@ -175,7 +175,7 @@ mod imp {
use rand::Rng;
use result::Result::{Ok};
use self::libc::{c_int, size_t};
use slice::{SlicePrelude};
use slice::SliceExt;
/// A random number generator that retrieves randomness straight from
/// the operating system. Platform sources:
@ -243,7 +243,7 @@ mod imp {
use result::Result::{Ok, Err};
use self::libc::{DWORD, BYTE, LPCSTR, BOOL};
use self::libc::types::os::arch::extra::{LONG_PTR};
use slice::{SlicePrelude};
use slice::SliceExt;
type HCRYPTPROV = LONG_PTR;

View File

@ -13,7 +13,7 @@
use io::Reader;
use rand::Rng;
use result::Result::{Ok, Err};
use slice::SlicePrelude;
use slice::SliceExt;
/// An RNG that reads random bytes straight from a `Reader`. This will
/// work best with an infinite reader, but this is not required.

View File

@ -232,13 +232,12 @@ fn demangle(writer: &mut Writer, s: &str) -> IoResult<()> {
/// all unix platforms we support right now, so it at least gets the job done.
#[cfg(unix)]
mod imp {
use prelude::*;
use c_str::CString;
use io::{IoResult, Writer};
use io::IoResult;
use libc;
use mem;
use option::Option;
use option::Option::{Some, None};
use result::Result::{Ok, Err};
use sync::{StaticMutex, MUTEX_INIT};
/// As always - iOS on arm uses SjLj exceptions and
@ -253,9 +252,7 @@ mod imp {
#[cfg(all(target_os = "ios", target_arch = "arm"))]
#[inline(never)]
pub fn write(w: &mut Writer) -> IoResult<()> {
use iter::{IteratorExt, range};
use result;
use slice::{SlicePrelude};
extern {
fn backtrace(buf: *mut *mut libc::c_void,
@ -389,12 +386,8 @@ mod imp {
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
fn print(w: &mut Writer, idx: int, addr: *mut libc::c_void) -> IoResult<()> {
use iter::IteratorExt;
use os;
use path::GenericPath;
use ptr::RawPtr;
use ptr;
use slice::{SlicePrelude};
////////////////////////////////////////////////////////////////////////
// libbacktrace.h API
@ -669,7 +662,7 @@ mod imp {
use path::Path;
use result::Result::{Ok, Err};
use sync::{StaticMutex, MUTEX_INIT};
use slice::SlicePrelude;
use slice::SliceExt;
use str::StrPrelude;
use dynamic_lib::DynamicLibrary;

View File

@ -14,7 +14,7 @@ use core::cmp::Ordering::{Equal, Less, Greater};
use core::option::Option;
use core::option::Option::{Some, None};
use core::slice;
use core::slice::SlicePrelude;
use core::slice::SliceExt;
use tables::normalization::{canonical_table, compatibility_table, composition_table};
fn bsearch_table<T>(c: char, r: &'static [(char, &'static [T])]) -> Option<&'static [T]> {

View File

@ -18,7 +18,7 @@ pub const UNICODE_VERSION: (uint, uint, uint) = (7, 0, 0);
fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
use core::cmp::Ordering::{Equal, Less, Greater};
use core::slice::SlicePrelude;
use core::slice::SliceExt;
r.binary_search(|&(lo,hi)| {
if lo <= c && c <= hi { Equal }
else if hi < c { Less }
@ -6825,7 +6825,7 @@ pub mod normalization {
fn bsearch_range_value_table(c: char, r: &'static [(char, char, u8)]) -> u8 {
use core::cmp::Ordering::{Equal, Less, Greater};
use core::slice::SlicePrelude;
use core::slice::SliceExt;
use core::slice;
match r.binary_search(|&(lo, hi, _)| {
if lo <= c && c <= hi { Equal }
@ -6958,7 +6958,7 @@ pub mod normalization {
pub mod conversions {
use core::cmp::Ordering::{Equal, Less, Greater};
use core::slice::SlicePrelude;
use core::slice::SliceExt;
use core::option::Option;
use core::option::Option::{Some, None};
use core::slice;
@ -7595,7 +7595,7 @@ pub mod conversions {
pub mod charwidth {
use core::option::Option;
use core::option::Option::{Some, None};
use core::slice::SlicePrelude;
use core::slice::SliceExt;
use core::slice;
fn bsearch_range_value_table(c: char, is_cjk: bool, r: &'static [(char, char, u8, u8)]) -> u8 {
@ -7801,8 +7801,8 @@ pub mod charwidth {
}
pub mod grapheme {
use core::slice::SlicePrelude;
use core::kinds::Copy;
use core::slice::SliceExt;
pub use self::GraphemeCat::*;
use core::slice;

View File

@ -17,7 +17,7 @@
use self::GraphemeState::*;
use core::cmp;
use core::slice::SlicePrelude;
use core::slice::SliceExt;
use core::iter::{Filter, AdditiveIterator, Iterator, IteratorExt};
use core::iter::{DoubleEndedIterator, DoubleEndedIteratorExt};
use core::kinds::Sized;