From 7741516a8bb206bf9357b70e12990a4dc1ba8169 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 11 Dec 2014 09:44:17 -0800 Subject: [PATCH] std: Collapse SlicePrelude traits This commit collapses the various prelude traits for slices into just one trait: * SlicePrelude/SliceAllocPrelude => SliceExt * CloneSlicePrelude/CloneSliceAllocPrelude => CloneSliceExt * OrdSlicePrelude/OrdSliceAllocPrelude => OrdSliceExt * PartialEqSlicePrelude => PartialEqSliceExt --- src/etc/unicode.py | 10 +- src/libcollections/hash/mod.rs | 2 +- src/libcollections/hash/sip.rs | 2 +- src/libcollections/lib.rs | 2 +- src/libcollections/slice.rs | 698 ++++++++++++++++++++++++++++- src/libcollections/str.rs | 14 +- src/libcollections/string.rs | 4 +- src/libcollections/vec.rs | 2 +- src/libcore/char.rs | 2 +- src/libcore/fmt/float.rs | 2 +- src/libcore/fmt/mod.rs | 2 +- src/libcore/fmt/num.rs | 2 +- src/libcore/prelude.rs | 4 +- src/libcore/slice.rs | 449 ++----------------- src/libcore/str.rs | 4 +- src/libgraphviz/maybe_owned_vec.rs | 17 +- src/libregex/vm.rs | 2 +- src/librustrt/c_str.rs | 6 +- src/libstd/ascii.rs | 2 +- src/libstd/collections/hash/set.rs | 2 +- src/libstd/dynamic_lib.rs | 4 +- src/libstd/io/buffered.rs | 2 +- src/libstd/io/comm_adapters.rs | 2 +- src/libstd/io/extensions.rs | 4 +- src/libstd/io/fs.rs | 2 +- src/libstd/io/mem.rs | 2 +- src/libstd/io/mod.rs | 2 +- src/libstd/io/net/ip.rs | 2 +- src/libstd/io/stdio.rs | 2 +- src/libstd/macros.rs | 2 +- src/libstd/num/strconv.rs | 8 +- src/libstd/os.rs | 6 +- src/libstd/path/mod.rs | 4 +- src/libstd/path/posix.rs | 4 +- src/libstd/path/windows.rs | 2 +- src/libstd/prelude.rs | 8 +- src/libstd/rand/os.rs | 6 +- src/libstd/rand/reader.rs | 2 +- src/libstd/rt/backtrace.rs | 15 +- src/libunicode/normalize.rs | 2 +- src/libunicode/tables.rs | 10 +- src/libunicode/u_str.rs | 2 +- 42 files changed, 782 insertions(+), 539 deletions(-) diff --git a/src/etc/unicode.py b/src/etc/unicode.py index 257cd80258246..63f1b3dcd4414 100755 --- a/src/etc/unicode.py +++ b/src/etc/unicode.py @@ -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 comp_pfun(char): 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 } diff --git a/src/libcollections/hash/mod.rs b/src/libcollections/hash/mod.rs index 637541a8fd654..446ebbbdbe988 100644 --- a/src/libcollections/hash/mod.rs +++ b/src/libcollections/hash/mod.rs @@ -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; diff --git a/src/libcollections/hash/sip.rs b/src/libcollections/hash/sip.rs index 9a7aa8c20d3a1..575e407fc2ab3 100644 --- a/src/libcollections/hash/sip.rs +++ b/src/libcollections/hash/sip.rs @@ -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}; diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index 039bbcd2b7020..274fa13d07449 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -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; diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 463e28b420d15..1ec3f1033e13e 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -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 Iterator> for Permutations { } /// Extension methods for boxed slices. -pub trait BoxedSlicePrelude { +pub trait BoxedSliceExt { /// Convert `self` into a vector without clones or allocation. fn into_vec(self) -> Vec; } -impl BoxedSlicePrelude for Box<[T]> { +impl BoxedSliceExt for Box<[T]> { #[experimental] fn into_vec(mut self) -> Vec { unsafe { @@ -291,7 +292,7 @@ impl BoxedSlicePrelude for Box<[T]> { } /// Allocating extension methods for slices containing `Clone` elements. -pub trait CloneSliceAllocPrelude for Sized? { +pub trait CloneSliceExt for Sized? { /// Copies `self` into a new `Vec`. fn to_vec(&self) -> Vec; @@ -324,9 +325,28 @@ pub trait CloneSliceAllocPrelude for Sized? { /// assert_eq!(Some(vec![3i, 1, 2]), perms.next()); /// ``` fn permutations(&self) -> Permutations; + + /// 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 CloneSliceAllocPrelude for [T] { +impl CloneSliceExt for [T] { /// Returns a copy of `v`. #[inline] fn to_vec(&self) -> Vec { @@ -360,6 +380,9 @@ impl CloneSliceAllocPrelude for [T] { } } + fn clone_from_slice(&mut self, src: &[T]) -> uint { + core_slice::CloneSliceExt::clone_from_slice(self, src) + } } fn insertion_sort(v: &mut [T], mut compare: F) where F: FnMut(&T, &T) -> Ordering { @@ -567,7 +590,7 @@ fn merge_sort(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 for Sized? { +pub trait OrdSliceExt 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 for Sized? { /// ``` #[experimental] fn sort(&mut self); -} -impl OrdSliceAllocPrelude for [T] { + /// 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 OrdSliceExt 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 for Sized? { +pub trait SliceExt for Sized? { /// Sorts the slice, in place, using `compare` to compare /// elements. /// @@ -636,9 +735,376 @@ pub trait SliceAllocPrelude for Sized? { /// assert!(a == [6i, 7, 8, 4, 5]); /// ``` fn move_from(&mut self, src: Vec, 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; + + /// 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(&self, pred: F) -> Splits + 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(&self, n: uint, pred: F) -> SplitsN> + 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(&self, n: uint, pred: F) -> SplitsN> + 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; + + /// 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; + + /// 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(&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; + + /// 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(&mut self, pred: F) -> MutSplits + 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(&mut self, n: uint, pred: F) -> SplitsN> + 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(&mut self, n: uint, pred: F) -> SplitsN> + 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; + + /// 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 SliceAllocPrelude for [T] { +impl SliceExt for [T] { #[inline] fn sort_by(&mut self, compare: F) where F: FnMut(&T, &T) -> Ordering { merge_sort(self, compare) @@ -651,6 +1117,208 @@ impl SliceAllocPrelude 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(&self, pred: F) -> Splits + where F: FnMut(&T) -> bool { + core_slice::SliceExt::split(self, pred) + } + + #[inline] + fn splitn(&self, n: uint, pred: F) -> SplitsN> + where F: FnMut(&T) -> bool { + core_slice::SliceExt::splitn(self, n, pred) + } + + #[inline] + fn rsplitn(&self, n: uint, pred: F) -> SplitsN> + 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(&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(&mut self, pred: F) -> MutSplits + where F: FnMut(&T) -> bool { + core_slice::SliceExt::split_mut(self, pred) + } + + #[inline] + fn splitn_mut(&mut self, n: uint, pred: F) -> SplitsN> + where F: FnMut(&T) -> bool { + core_slice::SliceExt::splitn_mut(self, n, pred) + } + + #[inline] + fn rsplitn_mut(&mut self, n: uint, pred: F) -> SplitsN> + 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"] diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 7664fb9c426ae..3c3a1291ba034 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -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) { diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index c4659f86680e4..857126b9e24f8 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -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}; @@ -1014,7 +1014,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}; diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 2ed8686394c01..c4c05969ed151 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -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. /// diff --git a/src/libcore/char.rs b/src/libcore/char.rs index 75f7991df027b..fbc444c2be354 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -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; diff --git a/src/libcore/fmt/float.rs b/src/libcore/fmt/float.rs index fb4d91e912a3b..d849bfa24c137 100644 --- a/src/libcore/fmt/float.rs +++ b/src/libcore/fmt/float.rs @@ -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. diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 37a1d4d564d84..c0a77c04716b9 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -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; diff --git a/src/libcore/fmt/num.rs b/src/libcore/fmt/num.rs index fa6f48326b56b..9cfa7bec22f67 100644 --- a/src/libcore/fmt/num.rs +++ b/src/libcore/fmt/num.rs @@ -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)] diff --git a/src/libcore/prelude.rs b/src/libcore/prelude.rs index 6678a20087b72..ff3fc870beb83 100644 --- a/src/libcore/prelude.rs +++ b/src/libcore/prelude.rs @@ -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}; diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 27a4328ba8017..a80cf9dab6444 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -61,377 +61,58 @@ use raw::Slice as RawSlice; // /// Extension methods for slices. -#[unstable = "may merge with other traits"] -pub trait SlicePrelude 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 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> 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> 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> + where P: FnMut(&T) -> bool; + fn rsplitn<'a, P>(&'a self, n: uint, pred: P) -> SplitsN> + 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(&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(&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> 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> 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

(&mut self, n: uint, pred: P) -> SplitsN> + where P: FnMut(&T) -> bool; + fn rsplitn_mut

(&mut self, n: uint, pred: P) -> SplitsN> + 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 SlicePrelude for [T] { +impl SliceExt for [T] { #[inline] fn slice(&self, start: uint, end: uint) -> &[T] { assert!(start <= end); @@ -789,7 +470,7 @@ impl ops::SliceMut for [T] { /// Extension methods for slices containing `PartialEq` elements. #[unstable = "may merge with other traits"] -pub trait PartialEqSlicePrelude for Sized? { +pub trait PartialEqSliceExt for Sized? { /// Find the first index containing a matching value. fn position_elem(&self, t: &T) -> Option; @@ -807,7 +488,7 @@ pub trait PartialEqSlicePrelude for Sized? { } #[unstable = "trait is unstable"] -impl PartialEqSlicePrelude for [T] { +impl PartialEqSliceExt for [T] { #[inline] fn position_elem(&self, x: &T) -> Option { self.iter().position(|y| *x == *y) @@ -838,75 +519,18 @@ impl PartialEqSlicePrelude for [T] { /// Extension methods for slices containing `Ord` elements. #[unstable = "may merge with other traits"] -pub trait OrdSlicePrelude 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 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 OrdSlicePrelude for [T] { +impl OrdSliceExt for [T] { #[unstable] fn binary_search_elem(&self, x: &T) -> BinarySearchResult { self.binary_search(|p| p.cmp(x)) @@ -977,31 +601,13 @@ impl OrdSlicePrelude for [T] { /// Extension methods for slices on Clone elements #[unstable = "may merge with other traits"] -pub trait CloneSlicePrelude 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 for Sized? { fn clone_from_slice(&mut self, &[T]) -> uint; } #[unstable = "trait is unstable"] -impl CloneSlicePrelude for [T] { +impl CloneSliceExt 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 CloneSlicePrelude 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? { diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 92f82bd977114..38a0b2a7c8ca2 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -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 diff --git a/src/libgraphviz/maybe_owned_vec.rs b/src/libgraphviz/maybe_owned_vec.rs index 7ebf9b6335208..cfa08e5f021f8 100644 --- a/src/libgraphviz/maybe_owned_vec.rs +++ b/src/libgraphviz/maybe_owned_vec.rs @@ -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 for MaybeOwnedVector<'a,T> { - /// Returns a copy of `self`. - fn to_vec(&self) -> Vec { - self.as_slice().to_vec() - } - - fn partitioned(&self, f: F) -> (Vec, Vec) where F: FnMut(&T) -> bool { - self.as_slice().partitioned(f) - } - - fn permutations(&self) -> Permutations { - self.as_slice().permutations() - } -} - impl<'a, T: Clone> Clone for MaybeOwnedVector<'a, T> { #[allow(deprecated)] fn clone(&self) -> MaybeOwnedVector<'a, T> { diff --git a/src/libregex/vm.rs b/src/libregex/vm.rs index 44cf2249b8e9b..15a678d2e7459 100644 --- a/src/libregex/vm.rs +++ b/src/libregex/vm.rs @@ -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, diff --git a/src/librustrt/c_str.rs b/src/librustrt/c_str.rs index bba81383f7b2e..18c5aefde506b 100644 --- a/src/librustrt/c_str.rs +++ b/src/librustrt/c_str.rs @@ -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; diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index ad2167214a7d4..342f5b87bd8a6 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -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; diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 745a8298ee8a5..c71f0d5b935f7 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -638,7 +638,7 @@ mod test_set { use prelude::*; use super::HashSet; - use slice::PartialEqSlicePrelude; + use slice::PartialEqSliceExt; #[test] fn test_disjoint() { diff --git a/src/libstd/dynamic_lib.rs b/src/libstd/dynamic_lib.rs index 059ad7537193f..758dab1a10726 100644 --- a/src/libstd/dynamic_lib.rs +++ b/src/libstd/dynamic_lib.rs @@ -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; diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index a8de7356fe7d1..0a1bf3090ba33 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -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; diff --git a/src/libstd/io/comm_adapters.rs b/src/libstd/io/comm_adapters.rs index 308dc09410138..2aa7435d871e2 100644 --- a/src/libstd/io/comm_adapters.rs +++ b/src/libstd/io/comm_adapters.rs @@ -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; diff --git a/src/libstd/io/extensions.rs b/src/libstd/io/extensions.rs index 69712e39d9108..24a000adef200 100644 --- a/src/libstd/io/extensions.rs +++ b/src/libstd/io/extensions.rs @@ -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(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); diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index da0834dc9ef37..40c28877548b9 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -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; diff --git a/src/libstd/io/mem.rs b/src/libstd/io/mem.rs index 4dc87278e2bbc..03d2af1b42644 100644 --- a/src/libstd/io/mem.rs +++ b/src/libstd/io/mem.rs @@ -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; diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 4baeaabc6c6a5..9706da739768d 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -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; diff --git a/src/libstd/io/net/ip.rs b/src/libstd/io/net/ip.rs index 62965c48a2680..092410fbc8eaa 100644 --- a/src/libstd/io/net/ip.rs +++ b/src/libstd/io/net/ip.rs @@ -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; diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 344012a09a0e3..950946da126de 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -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}; diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 900c223c70bd3..9cc165ce57092 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -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() }); diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index d5c27c7fbf82a..2b319640d1b4e 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -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; diff --git a/src/libstd/os.rs b/src/libstd/os.rs index a3ecfb49acee0..bf28b67f43067 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -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; diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index c7feff8705e5f..8f98329a4be72 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -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. diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 4041a6f60d71d..bea51712253e6 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -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}; diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 3983e365ae1f6..8b18d1d8cd4ce 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -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; diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index ec1cff73e96c6..8b6575b6bc1cc 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -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; diff --git a/src/libstd/rand/os.rs b/src/libstd/rand/os.rs index 5405892535cfe..bbe8edc0f007c 100644 --- a/src/libstd/rand/os.rs +++ b/src/libstd/rand/os.rs @@ -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; diff --git a/src/libstd/rand/reader.rs b/src/libstd/rand/reader.rs index ca6322247c2ab..7298b2ef0acc7 100644 --- a/src/libstd/rand/reader.rs +++ b/src/libstd/rand/reader.rs @@ -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. diff --git a/src/libstd/rt/backtrace.rs b/src/libstd/rt/backtrace.rs index 4ac09a071bbee..ad4695eb7fe6a 100644 --- a/src/libstd/rt/backtrace.rs +++ b/src/libstd/rt/backtrace.rs @@ -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; diff --git a/src/libunicode/normalize.rs b/src/libunicode/normalize.rs index 29a8b1204b856..d239cb8289682 100644 --- a/src/libunicode/normalize.rs +++ b/src/libunicode/normalize.rs @@ -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(c: char, r: &'static [(char, &'static [T])]) -> Option<&'static [T]> { diff --git a/src/libunicode/tables.rs b/src/libunicode/tables.rs index 7c78c777ddaa0..a219aefad192c 100644 --- a/src/libunicode/tables.rs +++ b/src/libunicode/tables.rs @@ -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; diff --git a/src/libunicode/u_str.rs b/src/libunicode/u_str.rs index 80311137b0165..5e98109c432aa 100644 --- a/src/libunicode/u_str.rs +++ b/src/libunicode/u_str.rs @@ -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;