auto merge of #18559 : aturon/rust/prelude_cleanup, r=alexcrichton

This commit renames a number of extension traits for slices and string slices, now that they have been refactored for DST. In many cases, multiple extension traits could now be consolidated. Further consolidation will be possible with generalized where clauses.

The renamings are consistent with the [new `-Prelude` suffix](https://github.com/rust-lang/rfcs/pull/344). There are probably a few more candidates for being renamed this way, but that is left for API stabilization of the relevant modules.

Because this renames traits, it is a:

[breaking-change]

However, I do not expect any code that currently uses the standard library to actually break.

Closes #17917
This commit is contained in:
bors 2014-11-06 16:52:09 +00:00
commit 8ed288edb2
45 changed files with 483 additions and 487 deletions

View File

@ -293,7 +293,7 @@ def emit_bsearch_range_table(f):
f.write("""
fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
use core::cmp::{Equal, Less, Greater};
use core::slice::ImmutableSlice;
use core::slice::SlicePrelude;
r.binary_search(|&(lo,hi)| {
if lo <= c && c <= hi { Equal }
else if hi < c { Less }
@ -351,7 +351,7 @@ def emit_conversions_module(f, lowerupper, upperlower):
f.write("pub mod conversions {")
f.write("""
use core::cmp::{Equal, Less, Greater};
use core::slice::ImmutableSlice;
use core::slice::SlicePrelude;
use core::tuple::Tuple2;
use core::option::{Option, Some, None};
use core::slice;
@ -390,7 +390,7 @@ def emit_conversions_module(f, lowerupper, upperlower):
def emit_grapheme_module(f, grapheme_table, grapheme_cats):
f.write("""pub mod grapheme {
use core::slice::ImmutableSlice;
use core::slice::SlicePrelude;
use core::slice;
#[allow(non_camel_case_types)]
@ -430,7 +430,7 @@ def emit_grapheme_module(f, grapheme_table, grapheme_cats):
def emit_charwidth_module(f, width_table):
f.write("pub mod charwidth {\n")
f.write(" use core::option::{Option, Some, None};\n")
f.write(" use core::slice::ImmutableSlice;\n")
f.write(" use core::slice::SlicePrelude;\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 {
@ -530,7 +530,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::{Equal, Less, Greater};
use core::slice::ImmutableSlice;
use core::slice::SlicePrelude;
use core::slice;
match r.binary_search(|&(lo, hi, _)| {
if lo <= c && c <= hi { Equal }

View File

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

View File

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

View File

@ -42,10 +42,10 @@
//!
//! ## Traits
//!
//! A number of traits add methods that allow you to accomplish tasks with slices.
//! These traits include `ImmutableSlice`, which is defined for `&[T]` types,
//! `MutableSlice`, defined for `&mut [T]` types, and `Slice` and `SliceMut`
//! which are defined for `[T]`.
//! A number of traits add methods that allow you to accomplish tasks
//! with slices, the most important being `SlicePrelude`. Other traits
//! apply only to slices of elements satisfying certain bounds (like
//! `Ord`).
//!
//! 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
@ -99,11 +99,11 @@ use core::iter::{range_step, MultiplicativeIterator};
use vec::Vec;
pub use core::slice::{Chunks, AsSlice, ImmutableSlice, ImmutablePartialEqSlice};
pub use core::slice::{ImmutableOrdSlice, MutableSlice, Items, MutItems};
pub use core::slice::{Chunks, AsSlice, SlicePrelude, PartialEqSlicePrelude};
pub use core::slice::{OrdSlicePrelude, SlicePrelude, Items, MutItems};
pub use core::slice::{ImmutableIntSlice, MutableIntSlice};
pub use core::slice::{MutSplits, MutChunks, Splits};
pub use core::slice::{bytes, mut_ref_slice, ref_slice, MutableCloneableSlice};
pub use core::slice::{bytes, mut_ref_slice, ref_slice, CloneSlicePrelude};
pub use core::slice::{Found, NotFound};
// Functional utilities
@ -266,29 +266,13 @@ impl<T: Clone> Iterator<Vec<T>> for Permutations<T> {
}
}
/// Extension methods for vector slices with cloneable elements
pub trait CloneableVector<T> for Sized? {
/// Copies `self` into a new `Vec`.
fn to_vec(&self) -> Vec<T>;
}
impl<T: Clone> CloneableVector<T> for [T] {
/// Returns a copy of `v`.
#[inline]
fn to_vec(&self) -> Vec<T> {
let mut vector = Vec::with_capacity(self.len());
vector.push_all(self);
vector
}
}
#[experimental]
pub trait BoxedSlice<T> {
/// Extension methods for boxed slices.
pub trait BoxedSlicePrelude<T> {
/// Convert `self` into a vector without clones or allocation.
fn into_vec(self) -> Vec<T>;
}
impl<T> BoxedSlice<T> for Box<[T]> {
impl<T> BoxedSlicePrelude<T> for Box<[T]> {
#[experimental]
fn into_vec(mut self) -> Vec<T> {
unsafe {
@ -299,8 +283,11 @@ impl<T> BoxedSlice<T> for Box<[T]> {
}
}
/// Extension methods for vectors containing `Clone` elements.
pub trait ImmutableCloneableVector<T> for Sized? {
/// Allocating extension methods for slices containing `Clone` elements.
pub trait CloneSliceAllocPrelude<T> for Sized? {
/// Copies `self` into a new `Vec`.
fn to_vec(&self) -> Vec<T>;
/// Partitions the vector into two vectors `(a, b)`, where all
/// elements of `a` satisfy `f` and all elements of `b` do not.
fn partitioned(&self, f: |&T| -> bool) -> (Vec<T>, Vec<T>);
@ -332,7 +319,16 @@ pub trait ImmutableCloneableVector<T> for Sized? {
fn permutations(&self) -> Permutations<T>;
}
impl<T: Clone> ImmutableCloneableVector<T> for [T] {
impl<T: Clone> CloneSliceAllocPrelude<T> for [T] {
/// Returns a copy of `v`.
#[inline]
fn to_vec(&self) -> Vec<T> {
let mut vector = Vec::with_capacity(self.len());
vector.push_all(self);
vector
}
#[inline]
fn partitioned(&self, f: |&T| -> bool) -> (Vec<T>, Vec<T>) {
let mut lefts = Vec::new();
@ -562,9 +558,36 @@ fn merge_sort<T>(v: &mut [T], compare: |&T, &T| -> Ordering) {
}
}
/// Extension methods for vectors such that their elements are
/// mutable.
pub trait MutableSliceAllocating<T> for Sized? {
/// Allocating extension methods for slices on Ord values.
#[experimental = "likely to merge with other traits"]
pub trait OrdSliceAllocPrelude<T> for Sized? {
/// Sorts the slice, in place.
///
/// This is equivalent to `self.sort_by(|a, b| a.cmp(b))`.
///
/// # Example
///
/// ```rust
/// let mut v = [-5i, 4, 1, -3, 2];
///
/// v.sort();
/// assert!(v == [-5i, -3, 1, 2, 4]);
/// ```
#[experimental]
fn sort(&mut self);
}
impl<T: Ord> OrdSliceAllocPrelude<T> for [T] {
#[experimental]
#[inline]
fn sort(&mut self) {
self.sort_by(|a, b| a.cmp(b))
}
}
/// Allocating extension methods for slices.
#[experimental = "likely to merge with other traits"]
pub trait SliceAllocPrelude<T> for Sized? {
/// Sorts the slice, in place, using `compare` to compare
/// elements.
///
@ -608,7 +631,7 @@ pub trait MutableSliceAllocating<T> for Sized? {
fn move_from(&mut self, src: Vec<T>, start: uint, end: uint) -> uint;
}
impl<T> MutableSliceAllocating<T> for [T] {
impl<T> SliceAllocPrelude<T> for [T] {
#[inline]
fn sort_by(&mut self, compare: |&T, &T| -> Ordering) {
merge_sort(self, compare)
@ -623,127 +646,6 @@ impl<T> MutableSliceAllocating<T> for [T] {
}
}
/// Methods for mutable vectors with orderable elements, such as
/// in-place sorting.
pub trait MutableOrdSlice<T> for Sized? {
/// Sorts the slice, in place.
///
/// This is equivalent to `self.sort_by(|a, b| a.cmp(b))`.
///
/// # Example
///
/// ```rust
/// let mut v = [-5i, 4, 1, -3, 2];
///
/// v.sort();
/// assert!(v == [-5i, -3, 1, 2, 4]);
/// ```
fn sort(&mut self);
/// 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);
/// ```
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);
/// ```
fn prev_permutation(&mut self) -> bool;
}
impl<T: Ord> MutableOrdSlice<T> for [T] {
#[inline]
fn sort(&mut self) {
self.sort_by(|a, b| a.cmp(b))
}
fn next_permutation(&mut self) -> bool {
// These cases only have 1 permutation each, so we can't do anything.
if self.len() < 2 { return false; }
// Step 1: Identify the longest, rightmost weakly decreasing part of the vector
let mut i = self.len() - 1;
while i > 0 && self[i-1] >= self[i] {
i -= 1;
}
// If that is the entire vector, this is the last-ordered permutation.
if i == 0 {
return false;
}
// Step 2: Find the rightmost element larger than the pivot (i-1)
let mut j = self.len() - 1;
while j >= i && self[j] <= self[i-1] {
j -= 1;
}
// Step 3: Swap that element with the pivot
self.swap(j, i-1);
// Step 4: Reverse the (previously) weakly decreasing part
self[mut i..].reverse();
true
}
fn prev_permutation(&mut self) -> bool {
// These cases only have 1 permutation each, so we can't do anything.
if self.len() < 2 { return false; }
// Step 1: Identify the longest, rightmost weakly increasing part of the vector
let mut i = self.len() - 1;
while i > 0 && self[i-1] <= self[i] {
i -= 1;
}
// If that is the entire vector, this is the first-ordered permutation.
if i == 0 {
return false;
}
// Step 2: Reverse the weakly increasing part
self[mut i..].reverse();
// Step 3: Find the rightmost element equal to or bigger than the pivot (i-1)
let mut j = self.len() - 1;
while j >= i && self[j-1] < self[i-1] {
j -= 1;
}
// Step 4: Swap that element with the pivot
self.swap(i-1, j);
true
}
}
/// Unsafe operations
pub mod raw {
pub use core::slice::raw::{buf_as_slice, mut_buf_as_slice};

View File

@ -56,8 +56,8 @@ use core::fmt;
use core::cmp;
use core::iter::AdditiveIterator;
use core::kinds::Sized;
use core::prelude::{Char, Clone, Eq, Equiv, ImmutableSlice};
use core::prelude::{Iterator, MutableSlice, None, Option, Ord, Ordering};
use core::prelude::{Char, Clone, Eq, Equiv};
use core::prelude::{Iterator, SlicePrelude, None, Option, Ord, Ordering};
use core::prelude::{PartialEq, PartialOrd, Result, AsSlice, Some, Tuple2};
use core::prelude::{range};
@ -73,8 +73,8 @@ pub use core::str::{CharSplitsN, AnyLines, MatchIndices, StrSplits};
pub use core::str::{Utf16CodeUnits, eq_slice, is_utf8, is_utf16, Utf16Items};
pub use core::str::{Utf16Item, ScalarValue, LoneSurrogate, utf16_items};
pub use core::str::{truncate_utf16_at_nul, utf8_char_width, CharRange};
pub use core::str::{Str, StrSlice};
pub use unicode::str::{UnicodeStrSlice, Words, Graphemes, GraphemeIndices};
pub use core::str::{Str, StrPrelude};
pub use unicode::str::{UnicodeStrPrelude, Words, Graphemes, GraphemeIndices};
/*
Section: Creating a string
@ -790,10 +790,10 @@ mod tests {
use std::iter::{Iterator, DoubleEndedIterator};
use super::*;
use std::slice::{AsSlice, ImmutableSlice};
use std::slice::{AsSlice, SlicePrelude};
use string::String;
use vec::Vec;
use slice::CloneableVector;
use slice::CloneSliceAllocPrelude;
use unicode::char::UnicodeChar;
@ -2240,8 +2240,8 @@ mod bench {
use test::black_box;
use super::*;
use std::iter::{Iterator, DoubleEndedIterator};
use std::str::StrSlice;
use std::slice::ImmutableSlice;
use std::str::StrPrelude;
use std::slice::SlicePrelude;
#[bench]
fn char_iterator(b: &mut Bencher) {

View File

@ -23,7 +23,7 @@ use core::ops;
use core::raw::Slice as RawSlice;
use hash;
use slice::CloneableVector;
use slice::CloneSliceAllocPrelude;
use str;
use str::{CharRange, StrAllocating, MaybeOwned, Owned};
use str::Slice as MaybeOwnedSlice; // So many `Slice`s...
@ -815,7 +815,7 @@ pub mod raw {
/// * A raw pointer is dereferenced and transmuted to `&[u8]`;
/// * The slice is not checked to see whether it contains valid UTF-8.
pub unsafe fn from_buf_len(buf: *const u8, len: uint) -> String {
use slice::CloneableVector;
use slice::CloneSliceAllocPrelude;
let slice: &[u8] = mem::transmute(Slice {
data: buf,
len: len,
@ -851,10 +851,10 @@ mod tests {
use test::Bencher;
use str;
use str::{Str, StrSlice, Owned};
use str::{Str, StrPrelude, Owned};
use super::{as_string, String};
use vec::Vec;
use slice::CloneableVector;
use slice::CloneSliceAllocPrelude;
#[test]
fn test_as_string() {

View File

@ -27,7 +27,7 @@ use core::ptr;
use core::raw::Slice as RawSlice;
use core::uint;
use slice::{CloneableVector};
use slice::{CloneSliceAllocPrelude};
/// An owned, growable vector.
///
@ -1389,7 +1389,7 @@ pub fn as_vec<'a, T>(x: &'a [T]) -> DerefVec<'a, T> {
pub mod raw {
use super::Vec;
use core::ptr;
use core::slice::MutableSlice;
use core::slice::SlicePrelude;
/// Constructs a vector from an unsafe pointer to a buffer.
///

View File

@ -18,7 +18,7 @@
use mem::transmute;
use option::{None, Option, Some};
use iter::range_step;
use slice::ImmutableSlice;
use slice::SlicePrelude;
// UTF-8 ranges and tags for encoding characters
static TAG_CONT: u8 = 0b1000_0000u8;

View File

@ -16,8 +16,8 @@ use iter::{range, DoubleEndedIterator};
use num::{Float, FPNaN, FPInfinite, ToPrimitive, Primitive};
use num::{Zero, One, cast};
use result::Ok;
use slice::{mod, ImmutableSlice, MutableSlice};
use str::StrSlice;
use slice::{mod, SlicePrelude};
use str::StrPrelude;
/// A flag that specifies whether to use exponential (scientific) notation.
pub enum ExponentFormat {

View File

@ -21,9 +21,9 @@ use option::{Option, Some, None};
use ops::Deref;
use result::{Ok, Err};
use result;
use slice::{AsSlice, ImmutableSlice};
use slice::{AsSlice, SlicePrelude};
use slice;
use str::StrSlice;
use str::StrPrelude;
use str;
pub use self::num::radix;

View File

@ -17,7 +17,7 @@
use fmt;
use iter::DoubleEndedIterator;
use num::{Int, cast, zero};
use slice::{ImmutableSlice, MutableSlice};
use slice::SlicePrelude;
/// A type that represents a specific radix
#[doc(hidden)]

View File

@ -57,9 +57,9 @@ pub use num::{Primitive, Int, ToPrimitive, FromPrimitive};
pub use option::{Option, Some, None};
pub use ptr::RawPtr;
pub use result::{Result, Ok, Err};
pub use str::{Str, StrSlice};
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::{ImmutablePartialEqSlice, ImmutableOrdSlice};
pub use slice::{AsSlice, ImmutableSlice, MutableSlice};
pub use slice::{PartialEqSlicePrelude, OrdSlicePrelude};
pub use slice::{AsSlice, SlicePrelude};

View File

@ -57,9 +57,9 @@ use raw::Slice as RawSlice;
// Extension traits
//
/// Extension methods for immutable slices.
#[unstable = "may merge with other traits; region parameter may disappear"]
pub trait ImmutableSlice<T> for Sized? {
/// Extension methods for slices.
#[unstable = "may merge with other traits"]
pub trait SlicePrelude<T> for Sized? {
/// Returns a subslice spanning the interval [`start`, `end`).
///
/// Fails when the end of the new slice lies beyond the end of the
@ -256,216 +256,12 @@ pub trait ImmutableSlice<T> for Sized? {
#[inline]
#[experimental = "not triaged yet"]
fn is_empty(&self) -> bool { self.len() == 0 }
}
#[unstable]
impl<T> ImmutableSlice<T> for [T] {
#[inline]
fn slice(&self, start: uint, end: uint) -> &[T] {
assert!(start <= end);
assert!(end <= self.len());
unsafe {
transmute(RawSlice {
data: self.as_ptr().offset(start as int),
len: (end - start)
})
}
}
#[inline]
fn slice_from(&self, start: uint) -> &[T] {
self.slice(start, self.len())
}
#[inline]
fn slice_to(&self, end: uint) -> &[T] {
self.slice(0, end)
}
#[inline]
fn split_at(&self, mid: uint) -> (&[T], &[T]) {
(self[..mid], self[mid..])
}
#[inline]
fn iter<'a>(&'a self) -> Items<'a, T> {
unsafe {
let p = self.as_ptr();
if mem::size_of::<T>() == 0 {
Items{ptr: p,
end: (p as uint + self.len()) as *const T,
marker: marker::ContravariantLifetime::<'a>}
} else {
Items{ptr: p,
end: p.offset(self.len() as int),
marker: marker::ContravariantLifetime::<'a>}
}
}
}
#[inline]
fn split<'a>(&'a self, pred: |&T|: 'a -> bool) -> Splits<'a, T> {
Splits {
v: self,
pred: pred,
finished: false
}
}
#[inline]
fn splitn<'a>(&'a self, n: uint, pred: |&T|: 'a -> bool) -> SplitsN<Splits<'a, T>> {
SplitsN {
iter: self.split(pred),
count: n,
invert: false
}
}
#[inline]
fn rsplitn<'a>(&'a self, n: uint, pred: |&T|: 'a -> bool) -> SplitsN<Splits<'a, T>> {
SplitsN {
iter: self.split(pred),
count: n,
invert: true
}
}
#[inline]
fn windows(&self, size: uint) -> Windows<T> {
assert!(size != 0);
Windows { v: self, size: size }
}
#[inline]
fn chunks(&self, size: uint) -> Chunks<T> {
assert!(size != 0);
Chunks { v: self, size: size }
}
#[inline]
fn get(&self, index: uint) -> Option<&T> {
if index < self.len() { Some(&self[index]) } else { None }
}
#[inline]
fn head(&self) -> Option<&T> {
if self.len() == 0 { None } else { Some(&self[0]) }
}
#[inline]
fn tail(&self) -> &[T] { self[1..] }
#[inline]
fn init(&self) -> &[T] {
self[..self.len() - 1]
}
#[inline]
fn last(&self) -> Option<&T> {
if self.len() == 0 { None } else { Some(&self[self.len() - 1]) }
}
#[inline]
unsafe fn unsafe_get(&self, index: uint) -> &T {
transmute(self.repr().data.offset(index as int))
}
#[inline]
fn as_ptr(&self) -> *const T {
self.repr().data
}
#[unstable]
fn binary_search(&self, f: |&T| -> Ordering) -> BinarySearchResult {
let mut base : uint = 0;
let mut lim : uint = self.len();
while lim != 0 {
let ix = base + (lim >> 1);
match f(&self[ix]) {
Equal => return Found(ix),
Less => {
base = ix + 1;
lim -= 1;
}
Greater => ()
}
lim >>= 1;
}
return NotFound(base);
}
#[inline]
fn len(&self) -> uint { self.repr().len }
}
impl<T> ops::Slice<uint, [T]> for [T] {
#[inline]
fn as_slice_<'a>(&'a self) -> &'a [T] {
self
}
#[inline]
fn slice_from_or_fail<'a>(&'a self, start: &uint) -> &'a [T] {
self.slice_or_fail(start, &self.len())
}
#[inline]
fn slice_to_or_fail<'a>(&'a self, end: &uint) -> &'a [T] {
self.slice_or_fail(&0, end)
}
#[inline]
fn slice_or_fail<'a>(&'a self, start: &uint, end: &uint) -> &'a [T] {
assert!(*start <= *end);
assert!(*end <= self.len());
unsafe {
transmute(RawSlice {
data: self.as_ptr().offset(*start as int),
len: (*end - *start)
})
}
}
}
impl<T> ops::SliceMut<uint, [T]> for [T] {
#[inline]
fn as_mut_slice_<'a>(&'a mut self) -> &'a mut [T] {
self
}
#[inline]
fn slice_from_or_fail_mut<'a>(&'a mut self, start: &uint) -> &'a mut [T] {
let len = &self.len();
self.slice_or_fail_mut(start, len)
}
#[inline]
fn slice_to_or_fail_mut<'a>(&'a mut self, end: &uint) -> &'a mut [T] {
self.slice_or_fail_mut(&0, end)
}
#[inline]
fn slice_or_fail_mut<'a>(&'a mut self, start: &uint, end: &uint) -> &'a mut [T] {
assert!(*start <= *end);
assert!(*end <= self.len());
unsafe {
transmute(RawSlice {
data: self.as_ptr().offset(*start as int),
len: (*end - *start)
})
}
}
}
/// Extension methods for slices such that their elements are
/// mutable.
#[experimental = "may merge with other traits; may lose region param; needs review"]
pub trait MutableSlice<T> for Sized? {
/// 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];
@ -626,8 +422,146 @@ pub trait MutableSlice<T> for Sized? {
fn as_mut_ptr(&mut self) -> *mut T;
}
#[experimental = "trait is experimental"]
impl<T> MutableSlice<T> for [T] {
#[unstable]
impl<T> SlicePrelude<T> for [T] {
#[inline]
fn slice(&self, start: uint, end: uint) -> &[T] {
assert!(start <= end);
assert!(end <= self.len());
unsafe {
transmute(RawSlice {
data: self.as_ptr().offset(start as int),
len: (end - start)
})
}
}
#[inline]
fn slice_from(&self, start: uint) -> &[T] {
self.slice(start, self.len())
}
#[inline]
fn slice_to(&self, end: uint) -> &[T] {
self.slice(0, end)
}
#[inline]
fn split_at(&self, mid: uint) -> (&[T], &[T]) {
(self[..mid], self[mid..])
}
#[inline]
fn iter<'a>(&'a self) -> Items<'a, T> {
unsafe {
let p = self.as_ptr();
if mem::size_of::<T>() == 0 {
Items{ptr: p,
end: (p as uint + self.len()) as *const T,
marker: marker::ContravariantLifetime::<'a>}
} else {
Items{ptr: p,
end: p.offset(self.len() as int),
marker: marker::ContravariantLifetime::<'a>}
}
}
}
#[inline]
fn split<'a>(&'a self, pred: |&T|: 'a -> bool) -> Splits<'a, T> {
Splits {
v: self,
pred: pred,
finished: false
}
}
#[inline]
fn splitn<'a>(&'a self, n: uint, pred: |&T|: 'a -> bool) -> SplitsN<Splits<'a, T>> {
SplitsN {
iter: self.split(pred),
count: n,
invert: false
}
}
#[inline]
fn rsplitn<'a>(&'a self, n: uint, pred: |&T|: 'a -> bool) -> SplitsN<Splits<'a, T>> {
SplitsN {
iter: self.split(pred),
count: n,
invert: true
}
}
#[inline]
fn windows(&self, size: uint) -> Windows<T> {
assert!(size != 0);
Windows { v: self, size: size }
}
#[inline]
fn chunks(&self, size: uint) -> Chunks<T> {
assert!(size != 0);
Chunks { v: self, size: size }
}
#[inline]
fn get(&self, index: uint) -> Option<&T> {
if index < self.len() { Some(&self[index]) } else { None }
}
#[inline]
fn head(&self) -> Option<&T> {
if self.len() == 0 { None } else { Some(&self[0]) }
}
#[inline]
fn tail(&self) -> &[T] { self[1..] }
#[inline]
fn init(&self) -> &[T] {
self[..self.len() - 1]
}
#[inline]
fn last(&self) -> Option<&T> {
if self.len() == 0 { None } else { Some(&self[self.len() - 1]) }
}
#[inline]
unsafe fn unsafe_get(&self, index: uint) -> &T {
transmute(self.repr().data.offset(index as int))
}
#[inline]
fn as_ptr(&self) -> *const T {
self.repr().data
}
#[unstable]
fn binary_search(&self, f: |&T| -> Ordering) -> BinarySearchResult {
let mut base : uint = 0;
let mut lim : uint = self.len();
while lim != 0 {
let ix = base + (lim >> 1);
match f(&self[ix]) {
Equal => return Found(ix),
Less => {
base = ix + 1;
lim -= 1;
}
Greater => ()
}
lim >>= 1;
}
return NotFound(base);
}
#[inline]
fn len(&self) -> uint { self.repr().len }
#[inline]
fn get_mut(&mut self, index: uint) -> Option<&mut T> {
if index < self.len() { Some(&mut self[index]) } else { None }
@ -764,9 +698,66 @@ impl<T> MutableSlice<T> for [T] {
}
}
impl<T> ops::Slice<uint, [T]> for [T] {
#[inline]
fn as_slice_<'a>(&'a self) -> &'a [T] {
self
}
#[inline]
fn slice_from_or_fail<'a>(&'a self, start: &uint) -> &'a [T] {
self.slice_or_fail(start, &self.len())
}
#[inline]
fn slice_to_or_fail<'a>(&'a self, end: &uint) -> &'a [T] {
self.slice_or_fail(&0, end)
}
#[inline]
fn slice_or_fail<'a>(&'a self, start: &uint, end: &uint) -> &'a [T] {
assert!(*start <= *end);
assert!(*end <= self.len());
unsafe {
transmute(RawSlice {
data: self.as_ptr().offset(*start as int),
len: (*end - *start)
})
}
}
}
impl<T> ops::SliceMut<uint, [T]> for [T] {
#[inline]
fn as_mut_slice_<'a>(&'a mut self) -> &'a mut [T] {
self
}
#[inline]
fn slice_from_or_fail_mut<'a>(&'a mut self, start: &uint) -> &'a mut [T] {
let len = &self.len();
self.slice_or_fail_mut(start, len)
}
#[inline]
fn slice_to_or_fail_mut<'a>(&'a mut self, end: &uint) -> &'a mut [T] {
self.slice_or_fail_mut(&0, end)
}
#[inline]
fn slice_or_fail_mut<'a>(&'a mut self, start: &uint, end: &uint) -> &'a mut [T] {
assert!(*start <= *end);
assert!(*end <= self.len());
unsafe {
transmute(RawSlice {
data: self.as_ptr().offset(*start as int),
len: (*end - *start)
})
}
}
}
/// Extension methods for slices containing `PartialEq` elements.
#[unstable = "may merge with other traits"]
pub trait ImmutablePartialEqSlice<T: PartialEq> for Sized? {
pub trait PartialEqSlicePrelude<T: PartialEq> for Sized? {
/// Find the first index containing a matching value.
fn position_elem(&self, t: &T) -> Option<uint>;
@ -784,7 +775,7 @@ pub trait ImmutablePartialEqSlice<T: PartialEq> for Sized? {
}
#[unstable = "trait is unstable"]
impl<T: PartialEq> ImmutablePartialEqSlice<T> for [T] {
impl<T: PartialEq> PartialEqSlicePrelude<T> for [T] {
#[inline]
fn position_elem(&self, x: &T) -> Option<uint> {
self.iter().position(|y| *x == *y)
@ -815,7 +806,7 @@ impl<T: PartialEq> ImmutablePartialEqSlice<T> for [T] {
/// Extension methods for slices containing `Ord` elements.
#[unstable = "may merge with other traits"]
pub trait ImmutableOrdSlice<T: Ord> for Sized? {
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
@ -842,19 +833,119 @@ pub trait ImmutableOrdSlice<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> ImmutableOrdSlice<T> for [T] {
impl<T: Ord> OrdSlicePrelude<T> for [T] {
#[unstable]
fn binary_search_elem(&self, x: &T) -> BinarySearchResult {
self.binary_search(|p| p.cmp(x))
}
#[experimental]
fn next_permutation(&mut self) -> bool {
// These cases only have 1 permutation each, so we can't do anything.
if self.len() < 2 { return false; }
// Step 1: Identify the longest, rightmost weakly decreasing part of the vector
let mut i = self.len() - 1;
while i > 0 && self[i-1] >= self[i] {
i -= 1;
}
// If that is the entire vector, this is the last-ordered permutation.
if i == 0 {
return false;
}
// Step 2: Find the rightmost element larger than the pivot (i-1)
let mut j = self.len() - 1;
while j >= i && self[j] <= self[i-1] {
j -= 1;
}
// Step 3: Swap that element with the pivot
self.swap(j, i-1);
// Step 4: Reverse the (previously) weakly decreasing part
self[mut i..].reverse();
true
}
#[experimental]
fn prev_permutation(&mut self) -> bool {
// These cases only have 1 permutation each, so we can't do anything.
if self.len() < 2 { return false; }
// Step 1: Identify the longest, rightmost weakly increasing part of the vector
let mut i = self.len() - 1;
while i > 0 && self[i-1] <= self[i] {
i -= 1;
}
// If that is the entire vector, this is the first-ordered permutation.
if i == 0 {
return false;
}
// Step 2: Reverse the weakly increasing part
self[mut i..].reverse();
// Step 3: Find the rightmost element equal to or bigger than the pivot (i-1)
let mut j = self.len() - 1;
while j >= i && self[j-1] < self[i-1] {
j -= 1;
}
// Step 4: Swap that element with the pivot
self.swap(i-1, j);
true
}
}
/// Trait for &[T] where T is Cloneable
/// Extension methods for slices on Clone elements
#[unstable = "may merge with other traits"]
pub trait MutableCloneableSlice<T> for Sized? {
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.
@ -862,7 +953,7 @@ pub trait MutableCloneableSlice<T> for Sized? {
/// # Example
///
/// ```rust
/// use std::slice::MutableCloneableSlice;
/// use std::slice::CloneSlicePrelude;
///
/// let mut dst = [0i, 0, 0];
/// let src = [1i, 2];
@ -878,7 +969,7 @@ pub trait MutableCloneableSlice<T> for Sized? {
}
#[unstable = "trait is unstable"]
impl<T: Clone> MutableCloneableSlice<T> for [T] {
impl<T: Clone> CloneSlicePrelude<T> for [T] {
#[inline]
fn clone_from_slice(&mut self, src: &[T]) -> uint {
let min = cmp::min(self.len(), src.len());
@ -1517,7 +1608,7 @@ pub mod raw {
pub mod bytes {
use kinds::Sized;
use ptr;
use slice::{ImmutableSlice, MutableSlice};
use slice::SlicePrelude;
/// A trait for operations on mutable `[u8]`s.
pub trait MutableByteVector for Sized? {

View File

@ -28,8 +28,7 @@ use kinds::Sized;
use num::{CheckedMul, Saturating};
use option::{Option, None, Some};
use raw::Repr;
use slice::ImmutableSlice;
use slice;
use slice::{mod, SlicePrelude};
use uint;
/*
@ -1056,8 +1055,8 @@ pub mod raw {
use mem;
use ptr::RawPtr;
use raw::Slice;
use slice::{ImmutableSlice};
use str::{is_utf8, StrSlice};
use slice::SlicePrelude;
use str::{is_utf8, StrPrelude};
/// Converts a slice of bytes to a string slice without checking
/// that the string contains valid UTF-8.
@ -1120,7 +1119,7 @@ pub mod traits {
use iter::Iterator;
use option::{Option, Some};
use ops;
use str::{Str, StrSlice, eq_slice};
use str::{Str, StrPrelude, eq_slice};
// NOTE(stage0): remove impl after a snapshot
#[cfg(stage0)]
@ -1240,7 +1239,7 @@ impl<'a> Str for &'a str {
}
/// Methods for string slices
pub trait StrSlice for Sized? {
pub trait StrPrelude for Sized? {
/// Returns true if one string contains another
///
/// # Arguments
@ -1891,7 +1890,7 @@ fn slice_error_fail(s: &str, begin: uint, end: uint) -> ! {
begin, end, s);
}
impl StrSlice for str {
impl StrPrelude for str {
#[inline]
fn contains(&self, needle: &str) -> bool {
self.find_str(needle).is_some()

View File

@ -12,7 +12,7 @@ use std::default::Default;
use std::fmt;
use std::iter::FromIterator;
use std::path::BytesContainer;
use std::slice;
use std::slice::{mod, Permutations};
// Note 1: It is not clear whether the flexibility of providing both
// the `Growable` and `FixedLen` variants is sufficiently useful.
@ -137,11 +137,19 @@ impl<'a,T:fmt::Show> fmt::Show for MaybeOwnedVector<'a,T> {
}
}
impl<'a,T:Clone> CloneableVector<T> 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(&self, f: |&T| -> bool) -> (Vec<T>, Vec<T>) {
self.as_slice().partitioned(f)
}
fn permutations(&self) -> Permutations<T> {
self.as_slice().permutations()
}
}
impl<'a, T: Clone> Clone for MaybeOwnedVector<'a, T> {
@ -153,7 +161,6 @@ impl<'a, T: Clone> Clone for MaybeOwnedVector<'a, T> {
}
}
impl<'a, T> Default for MaybeOwnedVector<'a, T> {
fn default() -> MaybeOwnedVector<'a, T> {
Growable(Vec::new())

View File

@ -296,7 +296,7 @@ fn spawn_process_os(cfg: ProcessConfig,
use std::mem;
use std::iter::Iterator;
use std::str::StrSlice;
use std::str::StrPrelude;
if cfg.gid.is_some() || cfg.uid.is_some() {
return Err(IoError {

View File

@ -35,7 +35,7 @@
use std::cmp;
use std::mem;
use std::slice::MutableSlice;
use std::slice::SlicePrelude;
use compile::{
Program,
Match, OneChar, CharClass, Any, EmptyBegin, EmptyEnd, EmptyWordBoundary,

View File

@ -108,8 +108,8 @@ pub unsafe extern "C" fn memcmp(s1: *const u8, s2: *const u8, n: uint) -> i32 {
#[cfg(test)]
mod test {
use core::str::StrSlice;
use core::slice::{MutableSlice, ImmutableSlice};
use core::str::StrPrelude;
use core::slice::{SlicePrelude};
use super::{memcmp, memset, memcpy, memmove};

View File

@ -47,7 +47,7 @@ mod imp {
use core::prelude::*;
use alloc::boxed::Box;
use collections::slice::CloneableVector;
use collections::slice::CloneSliceAllocPrelude;
use collections::vec::Vec;
use core::mem;
use core::slice;

View File

@ -76,9 +76,9 @@ use collections::hash;
use core::fmt;
use core::kinds::{Sized, marker};
use core::mem;
use core::prelude::{Clone, Drop, Eq, ImmutableSlice, Iterator};
use core::prelude::{MutableSlice, None, Option, Ordering, PartialEq};
use core::prelude::{PartialOrd, RawPtr, Some, StrSlice, range};
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

@ -19,8 +19,8 @@ use fmt;
use iter::Iterator;
use mem;
use option::{Option, Some, None};
use slice::{ImmutableSlice, MutableSlice, AsSlice};
use str::{Str, StrSlice};
use slice::{SlicePrelude, AsSlice};
use str::{Str, StrPrelude};
use string::{mod, String};
use to_string::IntoStr;
use vec::Vec;
@ -578,7 +578,7 @@ mod tests {
use prelude::*;
use super::*;
use char::from_u32;
use str::StrSlice;
use str::StrPrelude;
macro_rules! v2ascii (
( [$($e:expr),*]) => (&[$(Ascii{chr:$e}),*]);

View File

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

View File

@ -28,7 +28,7 @@ use option::*;
use os;
use path::{Path,GenericPath};
use result::*;
use slice::{AsSlice,ImmutableSlice};
use slice::{AsSlice,SlicePrelude};
use str;
use string::String;
use vec::Vec;
@ -284,8 +284,8 @@ pub mod dl {
use os;
use ptr;
use result::{Ok, Err, Result};
use slice::ImmutableSlice;
use str::StrSlice;
use slice::SlicePrelude;
use str::StrPrelude;
use str;
use string::String;
use vec::Vec;

View File

@ -18,7 +18,7 @@ use iter::ExactSize;
use ops::Drop;
use option::{Some, None, Option};
use result::{Ok, Err};
use slice::{ImmutableSlice, MutableSlice};
use slice::{SlicePrelude};
use slice;
use vec::Vec;
@ -376,7 +376,7 @@ mod test {
use super::super::{IoResult, EndOfFile};
use super::super::mem::{MemReader, MemWriter, BufReader};
use self::test::Bencher;
use str::StrSlice;
use str::StrPrelude;
/// A type, free to create, primarily intended for benchmarking creation of
/// wrappers that, just for construction, don't need a Reader/Writer that

View File

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

View File

@ -22,7 +22,7 @@ use num::Int;
use option::{Option, Some, None};
use ptr::RawPtr;
use result::{Ok, Err};
use slice::{ImmutableSlice, AsSlice};
use slice::{SlicePrelude, AsSlice};
/// An iterator that reads a single byte on each iteration,
/// until `.read_byte()` returns `EndOfFile`.
@ -150,7 +150,7 @@ pub fn u64_to_be_bytes<T>(n: u64, size: uint, f: |v: &[u8]| -> T) -> T {
/// 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::MutableSlice;
use slice::SlicePrelude;
assert!(size <= 8u);

View File

@ -70,7 +70,7 @@ use path;
use result::{Err, Ok};
use rt::rtio::LocalIo;
use rt::rtio;
use slice::ImmutableSlice;
use slice::SlicePrelude;
use string::String;
use vec::Vec;
@ -951,7 +951,7 @@ mod test {
use path::Path;
use io;
use ops::Drop;
use str::StrSlice;
use str::StrPrelude;
macro_rules! check( ($e:expr) => (
match $e {

View File

@ -17,7 +17,7 @@ use option::None;
use result::{Err, Ok};
use io;
use io::{Reader, Writer, Seek, Buffer, IoError, SeekStyle, IoResult};
use slice::{mod, AsSlice, ImmutableSlice};
use slice::{mod, AsSlice, SlicePrelude};
use vec::Vec;
const BUF_CAPACITY: uint = 128;
@ -341,7 +341,7 @@ mod test {
use io::*;
use io;
use self::test::Bencher;
use str::StrSlice;
use str::StrPrelude;
#[test]
fn test_mem_writer() {

View File

@ -236,8 +236,8 @@ use os;
use boxed::Box;
use result::{Ok, Err, Result};
use rt::rtio;
use slice::{AsSlice, ImmutableSlice};
use str::{Str, StrSlice};
use slice::{AsSlice, SlicePrelude};
use str::{Str, StrPrelude};
use str;
use string::String;
use uint;

View File

@ -22,8 +22,8 @@ use io::net;
use iter::Iterator;
use option::{Option, None, Some};
use result::{Ok, Err};
use str::StrSlice;
use slice::{MutableCloneableSlice, MutableSlice, ImmutableSlice};
use str::StrPrelude;
use slice::{CloneSlicePrelude, SlicePrelude};
use vec::Vec;
pub type Port = u16;

View File

@ -41,8 +41,8 @@ use rt;
use rt::local::Local;
use rt::task::Task;
use rt::rtio::{DontClose, IoFactory, LocalIo, RtioFileStream, RtioTTY};
use slice::ImmutableSlice;
use str::StrSlice;
use slice::SlicePrelude;
use str::StrPrelude;
use uint;
// And so begins the tale of acquiring a uv handle to a stdio stream on all

View File

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

View File

@ -20,8 +20,8 @@ use num;
use num::{Int, Bounded};
use num::{Float, FPNaN, FPInfinite, ToPrimitive};
use option::{None, Option, Some};
use slice::{ImmutableSlice, MutableSlice, CloneableVector};
use str::StrSlice;
use slice::{SlicePrelude, CloneSliceAllocPrelude};
use str::StrPrelude;
use string::String;
use vec::Vec;

View File

@ -46,9 +46,9 @@ use path::{Path, GenericPath, BytesContainer};
use ptr::RawPtr;
use ptr;
use result::{Err, Ok, Result};
use slice::{AsSlice, ImmutableSlice, MutableSlice, ImmutablePartialEqSlice};
use slice::CloneableVector;
use str::{Str, StrSlice, StrAllocating};
use slice::{AsSlice, SlicePrelude, PartialEqSlicePrelude};
use slice::CloneSliceAllocPrelude;
use str::{Str, StrPrelude, StrAllocating};
use string::String;
use to_string::ToString;
use sync::atomic::{AtomicInt, INIT_ATOMIC_INT, SeqCst};
@ -146,9 +146,9 @@ pub mod windows {
use option::{None, Option};
use option;
use os::TMPBUF_SZ;
use slice::{MutableSlice, ImmutableSlice};
use slice::{SlicePrelude};
use string::String;
use str::StrSlice;
use str::StrPrelude;
use vec::Vec;
pub fn fill_utf16_buf_and_decode(f: |*mut u16, DWORD| -> DWORD)

View File

@ -74,10 +74,10 @@ use fmt;
use iter::Iterator;
use option::{Option, None, Some};
use str;
use str::{MaybeOwned, Str, StrSlice};
use str::{MaybeOwned, Str, StrPrelude};
use string::String;
use slice::{AsSlice, CloneableVector};
use slice::{ImmutablePartialEqSlice, ImmutableSlice};
use slice::{AsSlice, CloneSliceAllocPrelude};
use slice::{PartialEqSlicePrelude, SlicePrelude};
use vec::Vec;
/// Typedef for POSIX file paths.

View File

@ -20,8 +20,8 @@ use iter::{DoubleEndedIterator, AdditiveIterator, Extendable, Iterator, Map};
use option::{Option, None, Some};
use str::Str;
use str;
use slice::{CloneableVector, Splits, AsSlice, VectorVector,
ImmutablePartialEqSlice, ImmutableSlice};
use slice::{CloneSliceAllocPrelude, Splits, AsSlice, VectorVector,
PartialEqSlicePrelude, SlicePrelude};
use vec::Vec;
use super::{BytesContainer, GenericPath, GenericPathUnsafe};
@ -444,7 +444,7 @@ mod tests {
use super::*;
use mem;
use str;
use str::StrSlice;
use str::StrPrelude;
macro_rules! t(
(s: $path:expr, $exp:expr) => (

View File

@ -22,8 +22,8 @@ use io::Writer;
use iter::{AdditiveIterator, DoubleEndedIterator, Extendable, Iterator, Map};
use mem;
use option::{Option, Some, None};
use slice::{AsSlice, ImmutableSlice};
use str::{CharSplits, Str, StrAllocating, StrVector, StrSlice};
use slice::{AsSlice, SlicePrelude};
use str::{CharSplits, Str, StrAllocating, StrVector, StrPrelude};
use string::String;
use unicode::char::UnicodeChar;
use vec::Vec;

View File

@ -76,18 +76,15 @@
#[doc(no_inline)] pub use ptr::{RawPtr, RawMutPtr};
#[doc(no_inline)] pub use result::{Result, Ok, Err};
#[doc(no_inline)] pub use io::{Buffer, Writer, Reader, Seek};
#[doc(no_inline)] pub use str::{Str, StrVector, StrSlice};
#[doc(no_inline)] pub use str::{IntoMaybeOwned, StrAllocating, UnicodeStrSlice};
#[doc(no_inline)] pub use str::{Str, StrVector, StrPrelude};
#[doc(no_inline)] pub use str::{IntoMaybeOwned, StrAllocating, UnicodeStrPrelude};
#[doc(no_inline)] pub use to_string::{ToString, IntoStr};
#[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::{CloneableVector, ImmutableCloneableVector};
#[doc(no_inline)] pub use slice::{MutableCloneableSlice, MutableOrdSlice};
#[doc(no_inline)] pub use slice::{ImmutableSlice, MutableSlice};
#[doc(no_inline)] pub use slice::{ImmutablePartialEqSlice, ImmutableOrdSlice};
#[doc(no_inline)] pub use slice::{AsSlice, VectorVector, BoxedSlice};
#[doc(no_inline)] pub use slice::MutableSliceAllocating;
#[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 string::String;
#[doc(no_inline)] pub use vec::Vec;

View File

@ -69,7 +69,7 @@ mod imp {
use rand::Rng;
use result::{Ok};
use self::libc::{c_int, size_t};
use slice::{ImmutableSlice, MutableSlice};
use slice::{SlicePrelude};
/// A random number generator that retrieves randomness straight from
/// the operating system. Platform sources:
@ -137,7 +137,7 @@ mod imp {
use result::{Ok, Err};
use self::libc::{DWORD, BYTE, LPCSTR, BOOL};
use self::libc::types::os::arch::extra::{LONG_PTR};
use slice::{ImmutableSlice, MutableSlice};
use slice::{SlicePrelude};
type HCRYPTPROV = LONG_PTR;

View File

@ -13,7 +13,7 @@
use io::Reader;
use rand::Rng;
use result::{Ok, Err};
use slice::ImmutableSlice;
use slice::SlicePrelude;
/// 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

@ -18,7 +18,7 @@ use iter::Iterator;
use option::{Some, None};
use os;
use result::{Ok, Err};
use str::StrSlice;
use str::StrPrelude;
use sync::atomic;
use unicode::char::UnicodeChar;
@ -255,7 +255,7 @@ mod imp {
pub fn write(w: &mut Writer) -> IoResult<()> {
use iter::{Iterator, range};
use result;
use slice::{MutableSlice};
use slice::{SlicePrelude};
extern {
fn backtrace(buf: *mut *mut libc::c_void,
@ -394,7 +394,7 @@ mod imp {
use path::GenericPath;
use ptr::RawPtr;
use ptr;
use slice::{ImmutableSlice, MutableSlice};
use slice::{SlicePrelude};
////////////////////////////////////////////////////////////////////////
// libbacktrace.h API
@ -666,8 +666,8 @@ mod imp {
use path::Path;
use result::{Ok, Err};
use rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
use slice::ImmutableSlice;
use str::StrSlice;
use slice::SlicePrelude;
use str::StrPrelude;
use dynamic_lib::DynamicLibrary;
#[allow(non_snake_case)]

View File

@ -73,7 +73,7 @@ pub mod char {
}
pub mod str {
pub use u_str::{UnicodeStrSlice, Words, Graphemes, GraphemeIndices};
pub use u_str::{UnicodeStrPrelude, Words, Graphemes, GraphemeIndices};
}
// this lets us use #[deriving(Clone)]

View File

@ -16,7 +16,7 @@
use core::cmp::{Equal, Less, Greater};
use core::option::{Option, Some, None};
use core::slice;
use core::slice::ImmutableSlice;
use core::slice::SlicePrelude;
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

@ -13,12 +13,12 @@
#![allow(missing_doc, non_uppercase_statics, non_snake_case)]
/// The version of [Unicode](http://www.unicode.org/)
/// that the `UnicodeChar` and `UnicodeStrSlice` traits are based on.
/// that the `UnicodeChar` and `UnicodeStrPrelude` traits are based on.
pub const UNICODE_VERSION: (uint, uint, uint) = (7, 0, 0);
fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
use core::cmp::{Equal, Less, Greater};
use core::slice::ImmutableSlice;
use core::slice::SlicePrelude;
r.binary_search(|&(lo,hi)| {
if lo <= c && c <= hi { Equal }
else if hi < c { Less }
@ -6242,7 +6242,7 @@ pub mod normalization {
fn bsearch_range_value_table(c: char, r: &'static [(char, char, u8)]) -> u8 {
use core::cmp::{Equal, Less, Greater};
use core::slice::ImmutableSlice;
use core::slice::SlicePrelude;
use core::slice;
match r.binary_search(|&(lo, hi, _)| {
if lo <= c && c <= hi { Equal }
@ -6367,7 +6367,7 @@ pub mod normalization {
pub mod conversions {
use core::cmp::{Equal, Less, Greater};
use core::slice::ImmutableSlice;
use core::slice::SlicePrelude;
use core::tuple::Tuple2;
use core::option::{Option, Some, None};
use core::slice;
@ -6935,7 +6935,7 @@ pub mod conversions {
pub mod charwidth {
use core::option::{Option, Some, None};
use core::slice::ImmutableSlice;
use core::slice::SlicePrelude;
use core::slice;
fn bsearch_range_value_table(c: char, is_cjk: bool, r: &'static [(char, char, u8, u8)]) -> u8 {
@ -7134,7 +7134,7 @@ pub mod charwidth {
}
pub mod grapheme {
use core::slice::ImmutableSlice;
use core::slice::SlicePrelude;
use core::slice;
#[allow(non_camel_case_types)]

View File

@ -18,11 +18,11 @@
*/
use core::cmp;
use core::slice::ImmutableSlice;
use core::slice::SlicePrelude;
use core::iter::{Filter, AdditiveIterator, Iterator, DoubleEndedIterator};
use core::kinds::Sized;
use core::option::{Option, None, Some};
use core::str::{CharSplits, StrSlice};
use core::str::{CharSplits, StrPrelude};
use u_char;
use u_char::UnicodeChar;
use tables::grapheme::GraphemeCat;
@ -32,7 +32,7 @@ pub type Words<'a> =
Filter<'a, &'a str, CharSplits<'a, extern "Rust" fn(char) -> bool>>;
/// Methods for Unicode string slices
pub trait UnicodeStrSlice for Sized? {
pub trait UnicodeStrPrelude for Sized? {
/// Returns an iterator over the
/// [grapheme clusters](http://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries)
/// of the string.
@ -129,7 +129,7 @@ pub trait UnicodeStrSlice for Sized? {
fn trim_right<'a>(&'a self) -> &'a str;
}
impl UnicodeStrSlice for str {
impl UnicodeStrPrelude for str {
#[inline]
fn graphemes(&self, is_extended: bool) -> Graphemes {
Graphemes { string: self, extended: is_extended, cat: None, catb: None }