diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs index aa96f3e272712..f6cd217b580cd 100644 --- a/src/compiletest/header.rs +++ b/src/compiletest/header.rs @@ -233,7 +233,7 @@ fn parse_exec_env(line: &str) -> Option<(String, String)> { parse_name_value_directive(line, "exec-env").map(|nv| { // nv is either FOO or FOO=BAR let mut strs: Vec = nv.as_slice() - .splitn('=', 1) + .splitn(1, '=') .map(|s| s.to_string()) .collect(); diff --git a/src/etc/unicode.py b/src/etc/unicode.py index 5424cd3b3ab98..7663cd1e3466a 100755 --- a/src/etc/unicode.py +++ b/src/etc/unicode.py @@ -293,13 +293,12 @@ 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::ImmutableVector; - use core::option::None; - r.bsearch(|&(lo,hi)| { + use core::slice::ImmutableSlice; + r.binary_search(|&(lo,hi)| { if lo <= c && c <= hi { Equal } else if hi < c { Less } else { Greater } - }) != None + }).found().is_some() }\n """) @@ -352,9 +351,10 @@ def emit_conversions_module(f, lowerupper, upperlower): f.write("pub mod conversions {") f.write(""" use core::cmp::{Equal, Less, Greater}; - use core::slice::ImmutableVector; + use core::slice::ImmutableSlice; use core::tuple::Tuple2; use core::option::{Option, Some, None}; + use core::slice; pub fn to_lower(c: char) -> char { match bsearch_case_table(c, LuLl_table) { @@ -371,11 +371,14 @@ def emit_conversions_module(f, lowerupper, upperlower): } fn bsearch_case_table(c: char, table: &'static [(char, char)]) -> Option { - table.bsearch(|&(key, _)| { + match table.binary_search(|&(key, _)| { if c == key { Equal } else if key < c { Less } else { Greater } - }) + }) { + slice::Found(i) => Some(i), + slice::NotFound(_) => None, + } } """) @@ -387,8 +390,8 @@ def emit_conversions_module(f, lowerupper, upperlower): def emit_grapheme_module(f, grapheme_table, grapheme_cats): f.write("""pub mod grapheme { - use core::option::{Some, None}; - use core::slice::ImmutableVector; + use core::slice::ImmutableSlice; + use core::slice; #[allow(non_camel_case_types)] #[deriving(Clone)] @@ -400,16 +403,16 @@ def emit_grapheme_module(f, grapheme_table, grapheme_cats): fn bsearch_range_value_table(c: char, r: &'static [(char, char, GraphemeCat)]) -> GraphemeCat { use core::cmp::{Equal, Less, Greater}; - match r.bsearch(|&(lo, hi, _)| { + match r.binary_search(|&(lo, hi, _)| { if lo <= c && c <= hi { Equal } else if hi < c { Less } else { Greater } }) { - Some(idx) => { + slice::Found(idx) => { let (_, _, cat) = r[idx]; cat } - None => GC_Any + slice::NotFound(_) => GC_Any } } @@ -427,20 +430,21 @@ 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::ImmutableVector;\n") + f.write(" use core::slice::ImmutableSlice;\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 { use core::cmp::{Equal, Less, Greater}; - match r.bsearch(|&(lo, hi, _, _)| { + match r.binary_search(|&(lo, hi, _, _)| { if lo <= c && c <= hi { Equal } else if hi < c { Less } else { Greater } }) { - Some(idx) => { + slice::Found(idx) => { let (_, _, r_ncjk, r_cjk) = r[idx]; if is_cjk { r_cjk } else { r_ncjk } } - None => 1 + slice::NotFound(_) => 1 } } """) @@ -525,19 +529,19 @@ def comp_pfun(char): f.write(""" fn bsearch_range_value_table(c: char, r: &'static [(char, char, u8)]) -> u8 { - use core::option::{Some, None}; use core::cmp::{Equal, Less, Greater}; - use core::slice::ImmutableVector; - match r.bsearch(|&(lo, hi, _)| { + use core::slice::ImmutableSlice; + use core::slice; + match r.binary_search(|&(lo, hi, _)| { if lo <= c && c <= hi { Equal } else if hi < c { Less } else { Greater } }) { - Some(idx) => { + slice::Found(idx) => { let (_, _, result) = r[idx]; result } - None => 0 + slice::NotFound(_) => 0 } }\n """) diff --git a/src/libcollections/hash/mod.rs b/src/libcollections/hash/mod.rs index 6f8b63953e2b4..dd07e718af418 100644 --- a/src/libcollections/hash/mod.rs +++ b/src/libcollections/hash/mod.rs @@ -296,7 +296,7 @@ mod tests { use std::prelude::*; use std::mem; - use slice::ImmutableVector; + use slice::ImmutableSlice; use super::{Hash, Hasher, Writer}; struct MyWriterHasher; diff --git a/src/libcollections/hash/sip.rs b/src/libcollections/hash/sip.rs index 485dc8c5959b7..b31d811c2c966 100644 --- a/src/libcollections/hash/sip.rs +++ b/src/libcollections/hash/sip.rs @@ -275,7 +275,7 @@ mod tests { use str::Str; use string::String; - use slice::{Vector, ImmutableVector}; + use slice::{Slice, ImmutableSlice}; use vec::Vec; use super::super::{Hash, Writer}; diff --git a/src/libcollections/ringbuf.rs b/src/libcollections/ringbuf.rs index ce08f169366da..354beb56d2dc3 100644 --- a/src/libcollections/ringbuf.rs +++ b/src/libcollections/ringbuf.rs @@ -362,6 +362,7 @@ pub struct MutItems<'a, T> { impl<'a, T> Iterator<&'a mut T> for MutItems<'a, T> { #[inline] + #[allow(deprecated)] // mut_shift_ref fn next(&mut self) -> Option<&'a mut T> { if self.nelts == 0 { return None; @@ -384,6 +385,7 @@ impl<'a, T> Iterator<&'a mut T> for MutItems<'a, T> { impl<'a, T> DoubleEndedIterator<&'a mut T> for MutItems<'a, T> { #[inline] + #[allow(deprecated)] // mut_shift_ref fn next_back(&mut self) -> Option<&'a mut T> { if self.nelts == 0 { return None; diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 4c7c7e3ea74bb..aac5b24fa6f02 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -45,8 +45,8 @@ represents iteration over a slice. ## Traits A number of traits add methods that allow you to accomplish tasks with slices. -These traits include `ImmutableVector`, which is defined for `&[T]` types, -and `MutableVector`, defined for `&mut [T]` types. +These traits include `ImmutableSlice`, which is defined for `&[T]` types, +and `MutableSlice`, defined for `&mut [T]` types. An example is the method `.slice(a, b)` that returns an immutable "view" into a `Vec` or another slice from the index interval `[a, b)`: @@ -98,10 +98,11 @@ use {Collection, MutableSeq}; use vec::Vec; pub use core::slice::{ref_slice, mut_ref_slice, Splits, Windows}; -pub use core::slice::{Chunks, Vector, ImmutableVector, ImmutableEqVector}; -pub use core::slice::{ImmutableOrdVector, MutableVector, Items, MutItems}; +pub use core::slice::{Chunks, Slice, ImmutableSlice, ImmutablePartialEqSlice}; +pub use core::slice::{ImmutableOrdSlice, MutableSlice, Items, MutItems}; pub use core::slice::{MutSplits, MutChunks}; -pub use core::slice::{bytes, MutableCloneableVector}; +pub use core::slice::{bytes, MutableCloneableSlice}; +pub use core::slice::{BinarySearchResult, Found, NotFound}; // Functional utilities @@ -116,7 +117,7 @@ pub trait VectorVector { fn connect_vec(&self, sep: &T) -> Vec; } -impl<'a, T: Clone, V: Vector> VectorVector for &'a [V] { +impl<'a, T: Clone, V: Slice> VectorVector for &'a [V] { fn concat_vec(&self) -> Vec { let size = self.iter().fold(0u, |acc, v| acc + v.as_slice().len()); let mut result = Vec::with_capacity(size); @@ -558,7 +559,7 @@ fn merge_sort(v: &mut [T], compare: |&T, &T| -> Ordering) { /// Extension methods for vectors such that their elements are /// mutable. -pub trait MutableVectorAllocating<'a, T> { +pub trait MutableSliceAllocating<'a, T> { /// Sort the vector, in place, using `compare` to compare /// elements. /// @@ -604,7 +605,7 @@ pub trait MutableVectorAllocating<'a, T> { fn move_from(self, src: Vec, start: uint, end: uint) -> uint; } -impl<'a,T> MutableVectorAllocating<'a, T> for &'a mut [T] { +impl<'a,T> MutableSliceAllocating<'a, T> for &'a mut [T] { #[inline] fn sort_by(self, compare: |&T, &T| -> Ordering) { merge_sort(self, compare) @@ -621,7 +622,7 @@ impl<'a,T> MutableVectorAllocating<'a, T> for &'a mut [T] { /// Methods for mutable vectors with orderable elements, such as /// in-place sorting. -pub trait MutableOrdVector { +pub trait MutableOrdSlice { /// Sort the vector, in place. /// /// This is equivalent to `self.sort_by(|a, b| a.cmp(b))`. @@ -667,7 +668,7 @@ pub trait MutableOrdVector { fn prev_permutation(self) -> bool; } -impl<'a, T: Ord> MutableOrdVector for &'a mut [T] { +impl<'a, T: Ord> MutableOrdSlice for &'a mut [T] { #[inline] fn sort(self) { self.sort_by(|a,b| a.cmp(b)) diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index d911ca6bb14f9..60ee8cc04f74c 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -894,7 +894,7 @@ mod tests { use {Collection, MutableSeq}; use super::*; - use std::slice::{Vector, ImmutableVector}; + use std::slice::{Slice, ImmutableSlice}; use string::String; use vec::Vec; @@ -1812,17 +1812,17 @@ mod tests { fn test_splitn_char_iterator() { let data = "\nMäry häd ä little lämb\nLittle lämb\n"; - let split: Vec<&str> = data.splitn(' ', 3).collect(); + let split: Vec<&str> = data.splitn(3, ' ').collect(); assert_eq!(split, vec!["\nMäry", "häd", "ä", "little lämb\nLittle lämb\n"]); - let split: Vec<&str> = data.splitn(|c: char| c == ' ', 3).collect(); + let split: Vec<&str> = data.splitn(3, |c: char| c == ' ').collect(); assert_eq!(split, vec!["\nMäry", "häd", "ä", "little lämb\nLittle lämb\n"]); // Unicode - let split: Vec<&str> = data.splitn('ä', 3).collect(); + let split: Vec<&str> = data.splitn(3, 'ä').collect(); assert_eq!(split, vec!["\nM", "ry h", "d ", " little lämb\nLittle lämb\n"]); - let split: Vec<&str> = data.splitn(|c: char| c == 'ä', 3).collect(); + let split: Vec<&str> = data.splitn(3, |c: char| c == 'ä').collect(); assert_eq!(split, vec!["\nM", "ry h", "d ", " little lämb\nLittle lämb\n"]); } @@ -1830,20 +1830,20 @@ mod tests { fn test_rsplitn_char_iterator() { let data = "\nMäry häd ä little lämb\nLittle lämb\n"; - let mut split: Vec<&str> = data.rsplitn(' ', 3).collect(); + let mut split: Vec<&str> = data.rsplitn(3, ' ').collect(); split.reverse(); assert_eq!(split, vec!["\nMäry häd ä", "little", "lämb\nLittle", "lämb\n"]); - let mut split: Vec<&str> = data.rsplitn(|c: char| c == ' ', 3).collect(); + let mut split: Vec<&str> = data.rsplitn(3, |c: char| c == ' ').collect(); split.reverse(); assert_eq!(split, vec!["\nMäry häd ä", "little", "lämb\nLittle", "lämb\n"]); // Unicode - let mut split: Vec<&str> = data.rsplitn('ä', 3).collect(); + let mut split: Vec<&str> = data.rsplitn(3, 'ä').collect(); split.reverse(); assert_eq!(split, vec!["\nMäry häd ", " little l", "mb\nLittle l", "mb\n"]); - let mut split: Vec<&str> = data.rsplitn(|c: char| c == 'ä', 3).collect(); + let mut split: Vec<&str> = data.rsplitn(3, |c: char| c == 'ä').collect(); split.reverse(); assert_eq!(split, vec!["\nMäry häd ", " little l", "mb\nLittle l", "mb\n"]); } diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 952f28da2af89..3b9e2ac72dc4b 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -18,12 +18,15 @@ use core::default::Default; use core::fmt; use core::mem; use core::ptr; -use core::raw::Slice; +// FIXME: ICE's abound if you import the `Slice` type while importing `Slice` trait +use RawSlice = core::raw::Slice; +use core::slice::Slice; use {Collection, Mutable, MutableSeq}; use hash; use str; -use str::{CharRange, StrAllocating, MaybeOwned, Owned, Slice}; +use str::{CharRange, StrAllocating, MaybeOwned, Owned}; +use MaybeOwnedSlice = str::Slice; // So many `Slice`s... use vec::Vec; /// A growable string stored as a UTF-8 encoded buffer. @@ -130,7 +133,7 @@ impl String { /// ``` pub fn from_utf8_lossy<'a>(v: &'a [u8]) -> MaybeOwned<'a> { if str::is_utf8(v) { - return Slice(unsafe { mem::transmute(v) }) + return MaybeOwnedSlice(unsafe { mem::transmute(v) }) } static TAG_CONT_U8: u8 = 128u8; @@ -138,7 +141,7 @@ impl String { let mut i = 0; let total = v.len(); fn unsafe_get(xs: &[u8], i: uint) -> u8 { - unsafe { *xs.unsafe_ref(i) } + unsafe { *xs.unsafe_get(i) } } fn safe_get(xs: &[u8], i: uint, total: uint) -> u8 { if i >= total { @@ -496,7 +499,7 @@ impl String { unsafe { // Attempt to not use an intermediate buffer by just pushing bytes // directly onto this string. - let slice = Slice { + let slice = RawSlice { data: self.vec.as_ptr().offset(cur_len as int), len: 4, }; diff --git a/src/libcollections/trie.rs b/src/libcollections/trie.rs index c3dcebfc815b1..dcfe256807467 100644 --- a/src/libcollections/trie.rs +++ b/src/libcollections/trie.rs @@ -926,7 +926,7 @@ macro_rules! iterator_impl { // such thing as invalid pointers and memory unsafety. The // reason is performance, without doing this we can get the // bench_iter_large microbenchmark down to about 30000 ns/iter - // (using .unsafe_ref to index self.stack directly, 38000 + // (using .unsafe_get to index self.stack directly, 38000 // ns/iter with [] checked indexing), but this smashes that down // to 13500 ns/iter. // diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 6bda0eed66dd9..b49e8aa01bb41 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -13,7 +13,8 @@ use core::prelude::*; use alloc::heap::{allocate, reallocate, deallocate}; -use core::raw::Slice; +use RawSlice = core::raw::Slice; +use core::slice::Slice; use core::cmp::max; use core::default::Default; use core::fmt; @@ -24,7 +25,7 @@ use core::ptr; use core::uint; use {Collection, Mutable, MutableSeq}; -use slice::{MutableOrdVector, MutableVectorAllocating, CloneableVector}; +use slice::{MutableOrdSlice, MutableSliceAllocating, CloneableVector}; use slice::{Items, MutItems}; @@ -347,7 +348,7 @@ impl Vec { unsafe { ptr::write( self.as_mut_slice().unsafe_mut_ref(len), - other.unsafe_ref(i).clone()); + other.unsafe_get(i).clone()); self.set_len(len + 1); } } @@ -506,7 +507,7 @@ impl PartialOrd for Vec { impl Eq for Vec {} -impl> Equiv for Vec { +impl> Equiv for Vec { #[inline] fn equiv(&self, other: &V) -> bool { self.as_slice() == other.as_slice() } } @@ -702,7 +703,7 @@ impl Vec { // decrement len before the read(), so a failure on Drop doesn't // re-drop the just-failed value. self.len -= 1; - ptr::read(self.as_slice().unsafe_ref(self.len)); + ptr::read(self.as_slice().unsafe_get(self.len)); } } } @@ -720,7 +721,7 @@ impl Vec { #[inline] pub fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] { unsafe { - mem::transmute(Slice { + mem::transmute(RawSlice { data: self.as_mut_ptr() as *const T, len: self.len, }) @@ -911,8 +912,9 @@ impl Vec { /// assert!(vec.tailn(2) == [3, 4]); /// ``` #[inline] + #[deprecated = "use slice_from"] pub fn tailn<'a>(&'a self, n: uint) -> &'a [T] { - self.as_slice().tailn(n) + self.as_slice().slice_from(n) } /// Returns a reference to the last element of a vector, or `None` if it is @@ -1502,7 +1504,7 @@ impl Vec { } } -impl Vector for Vec { +impl Slice for Vec { /// Work with `self` as a slice. /// /// # Example @@ -1515,11 +1517,11 @@ impl Vector for Vec { /// ``` #[inline] fn as_slice<'a>(&'a self) -> &'a [T] { - unsafe { mem::transmute(Slice { data: self.as_ptr(), len: self.len }) } + unsafe { mem::transmute(RawSlice { data: self.as_ptr(), len: self.len }) } } } -impl> Add> for Vec { +impl> Add> for Vec { #[inline] fn add(&self, rhs: &V) -> Vec { let mut res = Vec::with_capacity(self.len() + rhs.as_slice().len()); @@ -1604,7 +1606,7 @@ impl MutableSeq for Vec { } else { unsafe { self.len -= 1; - Some(ptr::read(self.as_slice().unsafe_ref(self.len()))) + Some(ptr::read(self.as_slice().unsafe_get(self.len()))) } } } diff --git a/src/libcore/fmt/float.rs b/src/libcore/fmt/float.rs index 1bfa5168cf796..3a07e43e50993 100644 --- a/src/libcore/fmt/float.rs +++ b/src/libcore/fmt/float.rs @@ -17,7 +17,7 @@ use iter::{range, DoubleEndedIterator}; use num::{Float, FPNaN, FPInfinite, ToPrimitive, Primitive}; use num::{Zero, One, cast}; use result::Ok; -use slice::{ImmutableVector, MutableVector}; +use slice::{ImmutableSlice, MutableSlice}; use slice; use str::StrSlice; diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 9cb64747c91b4..942f7f8b71019 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -24,7 +24,7 @@ use option::{Option, Some, None}; use ops::Deref; use result::{Ok, Err}; use result; -use slice::{Vector, ImmutableVector}; +use slice::{Slice, ImmutableSlice}; use slice; use str::StrSlice; use str; diff --git a/src/libcore/fmt/num.rs b/src/libcore/fmt/num.rs index bba3e4cb9afcc..21cbafdc60538 100644 --- a/src/libcore/fmt/num.rs +++ b/src/libcore/fmt/num.rs @@ -18,7 +18,7 @@ use collections::Collection; use fmt; use iter::DoubleEndedIterator; use num::{Int, cast, zero}; -use slice::{ImmutableVector, MutableVector}; +use slice::{ImmutableSlice, MutableSlice}; /// A type that represents a specific radix #[doc(hidden)] diff --git a/src/libcore/option.rs b/src/libcore/option.rs index f8293aeb03d19..74d87712a02ef 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -143,7 +143,7 @@ use cmp::{PartialEq, Eq, Ord}; use default::Default; -use slice::Vector; +use slice::Slice; use iter::{Iterator, DoubleEndedIterator, FromIterator, ExactSize}; use mem; use slice; @@ -518,7 +518,7 @@ impl Option { // Trait implementations ///////////////////////////////////////////////////////////////////////////// -impl Vector for Option { +impl Slice for Option { /// Convert from `Option` to `&[T]` (without copying) #[inline] fn as_slice<'a>(&'a self) -> &'a [T] { diff --git a/src/libcore/prelude.rs b/src/libcore/prelude.rs index 5b7c7c8f31a6f..ead48092c4dcf 100644 --- a/src/libcore/prelude.rs +++ b/src/libcore/prelude.rs @@ -61,6 +61,6 @@ pub use str::{Str, StrSlice}; pub use tuple::{Tuple1, Tuple2, Tuple3, Tuple4}; pub use tuple::{Tuple5, Tuple6, Tuple7, Tuple8}; pub use tuple::{Tuple9, Tuple10, Tuple11, Tuple12}; -pub use slice::{ImmutableEqVector, ImmutableOrdVector}; -pub use slice::{MutableVector}; -pub use slice::{Vector, ImmutableVector}; +pub use slice::{ImmutablePartialEqSlice, ImmutableOrdSlice}; +pub use slice::{MutableSlice}; +pub use slice::{Slice, ImmutableSlice}; diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index d3b761f9665d4..93dafc153b6b2 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -12,6 +12,7 @@ //! //! For more details `std::slice`. +#![stable] #![doc(primitive = "slice")] // How this module is organized. @@ -47,20 +48,25 @@ use ptr::RawPtr; use mem; use mem::size_of; use kinds::marker; -use raw::{Repr, Slice}; +use raw::Repr; +// Avoid conflicts with *both* the Slice trait (buggy) and the `slice::raw` module. +use RawSlice = raw::Slice; + // // Extension traits // /// Extension methods for vectors -pub trait ImmutableVector<'a, T> { +#[unstable = "may merge with other traits; region parameter may disappear"] +pub trait ImmutableSlice<'a, T> { /** * Returns a slice of self spanning the interval [`start`, `end`). * * Fails when the slice (or part of it) is outside the bounds of self, * or when `start` > `end`. */ + #[unstable] fn slice(&self, start: uint, end: uint) -> &'a [T]; /** @@ -68,6 +74,7 @@ pub trait ImmutableVector<'a, T> { * * Fails when `start` points outside the bounds of self. */ + #[unstable] fn slice_from(&self, start: uint) -> &'a [T]; /** @@ -75,6 +82,7 @@ pub trait ImmutableVector<'a, T> { * * Fails when `end` points outside the bounds of self. */ + #[unstable] fn slice_to(&self, end: uint) -> &'a [T]; /// Divides one slice into two at an index. @@ -84,24 +92,29 @@ pub trait ImmutableVector<'a, T> { /// indices from `[mid, len)` (excluding the index `len` itself). /// /// Fails if `mid > len`. + #[unstable] fn split_at(&self, mid: uint) -> (&'a [T], &'a [T]); /// Returns an iterator over the vector + #[unstable = "iterator type may change"] fn iter(self) -> Items<'a, T>; /// Returns an iterator over the subslices of the vector which are /// separated by elements that match `pred`. The matched element /// is not contained in the subslices. + #[unstable = "iterator type may change"] fn split(self, pred: |&T|: 'a -> bool) -> Splits<'a, T>; /// Returns an iterator over the subslices of the vector which are /// 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: |&T|: 'a -> bool) -> SplitsN<'a, T>; /// Returns an iterator over the subslices of the vector which are /// separated by elements that match `pred` limited to splitting /// at most `n` times. This starts at the end of the vector and /// works backwards. The matched element is not contained in the /// subslices. + #[unstable = "iterator type may change"] fn rsplitn(self, n: uint, pred: |&T|: 'a -> bool) -> SplitsN<'a, T>; /** @@ -126,6 +139,7 @@ pub trait ImmutableVector<'a, T> { * ``` * */ + #[unstable = "iterator type may change"] fn windows(self, size: uint) -> Windows<'a, T>; /** * @@ -151,28 +165,42 @@ pub trait ImmutableVector<'a, T> { * ``` * */ + #[unstable = "iterator type may change"] fn chunks(self, size: uint) -> Chunks<'a, T>; /// Returns the element of a vector at the given index, or `None` if the /// index is out of bounds + #[unstable] fn get(&self, index: uint) -> Option<&'a T>; /// Returns the first element of a vector, or `None` if it is empty + #[unstable = "name may change"] fn head(&self) -> Option<&'a T>; /// Returns all but the first element of a vector + #[unstable = "name may change"] fn tail(&self) -> &'a [T]; /// Returns all but the first `n' elements of a vector + #[deprecated = "use slice_from"] fn tailn(&self, n: uint) -> &'a [T]; /// Returns all but the last element of a vector + #[unstable = "name may change"] fn init(&self) -> &'a [T]; /// Returns all but the last `n' elements of a vector + #[deprecated = "use slice_to but note the arguments are different"] fn initn(&self, n: uint) -> &'a [T]; /// Returns the last element of a vector, or `None` if it is empty. + #[unstable = "name may change"] fn last(&self) -> Option<&'a T>; /// Returns a pointer to the element at the given index, without doing /// bounds checking. + #[deprecated = "renamed to `unsafe_get`"] unsafe fn unsafe_ref(self, index: uint) -> &'a T; + /// Returns a pointer to the element at the given index, without doing + /// bounds checking. + #[unstable] + unsafe fn unsafe_get(self, index: uint) -> &'a T; + /** * Returns an unsafe pointer to the vector's buffer * @@ -182,6 +210,7 @@ pub trait ImmutableVector<'a, T> { * Modifying the vector may cause its buffer to be reallocated, which * would also make any pointers to it invalid. */ + #[unstable] fn as_ptr(&self) -> *const T; /** @@ -195,8 +224,23 @@ pub trait ImmutableVector<'a, T> { * Returns the index where the comparator returned `Equal`, or `None` if * not found. */ + #[deprecated = "use binary_search"] fn bsearch(&self, f: |&T| -> Ordering) -> Option; + /// Binary search a sorted vector with a comparator function. + /// + /// The comparator function should implement an order consistent + /// with the sort order of the underlying vector, returning an + /// order code that indicates whether its argument is `Less`, + /// `Equal` or `Greater` the desired target. + /// + /// 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. + #[unstable] + fn binary_search(&self, f: |&T| -> Ordering) -> BinarySearchResult; + /** * Returns an immutable reference to the first element in this slice * and adjusts the slice in place so that it no longer contains @@ -213,6 +257,7 @@ pub trait ImmutableVector<'a, T> { * * Returns `None` if vector is empty */ + #[deprecated = "find some other way. sorry"] fn shift_ref(&mut self) -> Option<&'a T>; /** @@ -231,16 +276,18 @@ pub trait ImmutableVector<'a, T> { * * Returns `None` if slice is empty. */ + #[deprecated = "find some other way. sorry"] fn pop_ref(&mut self) -> Option<&'a T>; } -impl<'a,T> ImmutableVector<'a, T> for &'a [T] { +#[unstable] +impl<'a,T> ImmutableSlice<'a, T> for &'a [T] { #[inline] fn slice(&self, start: uint, end: uint) -> &'a [T] { assert!(start <= end); assert!(end <= self.len()); unsafe { - transmute(Slice { + transmute(RawSlice { data: self.as_ptr().offset(start as int), len: (end - start) }) @@ -331,6 +378,7 @@ impl<'a,T> ImmutableVector<'a, T> for &'a [T] { fn tail(&self) -> &'a [T] { self.slice(1, self.len()) } #[inline] + #[deprecated = "use slice_from"] fn tailn(&self, n: uint) -> &'a [T] { self.slice(n, self.len()) } #[inline] @@ -339,6 +387,7 @@ impl<'a,T> ImmutableVector<'a, T> for &'a [T] { } #[inline] + #[deprecated = "use slice_to but note the arguments are different"] fn initn(&self, n: uint) -> &'a [T] { self.slice(0, self.len() - n) } @@ -349,16 +398,23 @@ impl<'a,T> ImmutableVector<'a, T> for &'a [T] { } #[inline] + #[deprecated = "renamed to `unsafe_get`"] unsafe fn unsafe_ref(self, index: uint) -> &'a T { transmute(self.repr().data.offset(index as int)) } + #[inline] + unsafe fn unsafe_get(self, index: uint) -> &'a T { + transmute(self.repr().data.offset(index as int)) + } + #[inline] fn as_ptr(&self) -> *const T { self.repr().data } + #[deprecated = "use binary_search"] fn bsearch(&self, f: |&T| -> Ordering) -> Option { let mut base : uint = 0; let mut lim : uint = self.len(); @@ -378,9 +434,29 @@ impl<'a,T> ImmutableVector<'a, T> for &'a [T] { return None; } + #[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); + } + fn shift_ref(&mut self) -> Option<&'a T> { unsafe { - let s: &mut Slice = transmute(self); + let s: &mut RawSlice = transmute(self); match raw::shift_ptr(s) { Some(p) => Some(&*p), None => None @@ -390,7 +466,7 @@ impl<'a,T> ImmutableVector<'a, T> for &'a [T] { fn pop_ref(&mut self) -> Option<&'a T> { unsafe { - let s: &mut Slice = transmute(self); + let s: &mut RawSlice = transmute(self); match raw::pop_ptr(s) { Some(p) => Some(&*p), None => None @@ -401,7 +477,8 @@ impl<'a,T> ImmutableVector<'a, T> for &'a [T] { /// Extension methods for vectors such that their elements are /// mutable. -pub trait MutableVector<'a, T> { +#[experimental = "may merge with other traits; may lose region param; needs review"] +pub trait MutableSlice<'a, T> { /// Returns a mutable reference to the element at the given index, /// or `None` if the index is out of bounds fn get_mut(self, index: uint) -> Option<&'a mut T>; @@ -465,6 +542,7 @@ pub trait MutableVector<'a, T> { * * Returns `None` if slice is empty */ + #[deprecated = "find some other way. sorry"] fn mut_shift_ref(&mut self) -> Option<&'a mut T>; /** @@ -483,6 +561,7 @@ pub trait MutableVector<'a, T> { * * Returns `None` if slice is empty. */ + #[deprecated = "find some other way. sorry"] fn mut_pop_ref(&mut self) -> Option<&'a mut T>; /// Swaps two elements in a vector. @@ -607,7 +686,8 @@ pub trait MutableVector<'a, T> { unsafe fn copy_memory(self, src: &[T]); } -impl<'a,T> MutableVector<'a, T> for &'a mut [T] { +#[experimental = "trait is experimental"] +impl<'a,T> MutableSlice<'a, T> for &'a mut [T] { #[inline] fn get_mut(self, index: uint) -> Option<&'a mut T> { if index < self.len() { Some(&mut self[index]) } else { None } @@ -620,7 +700,7 @@ impl<'a,T> MutableVector<'a, T> for &'a mut [T] { assert!(start <= end); assert!(end <= self.len()); unsafe { - transmute(Slice { + transmute(RawSlice { data: self.as_mut_ptr().offset(start as int) as *const T, len: (end - start) }) @@ -685,7 +765,7 @@ impl<'a,T> MutableVector<'a, T> for &'a mut [T] { fn mut_shift_ref(&mut self) -> Option<&'a mut T> { unsafe { - let s: &mut Slice = transmute(self); + let s: &mut RawSlice = transmute(self); match raw::shift_ptr(s) { // FIXME #13933: this `&` -> `&mut` cast is a little // dubious @@ -697,7 +777,7 @@ impl<'a,T> MutableVector<'a, T> for &'a mut [T] { fn mut_pop_ref(&mut self) -> Option<&'a mut T> { unsafe { - let s: &mut Slice = transmute(self); + let s: &mut RawSlice = transmute(self); match raw::pop_ptr(s) { // FIXME #13933: this `&` -> `&mut` cast is a little // dubious @@ -755,7 +835,8 @@ impl<'a,T> MutableVector<'a, T> for &'a mut [T] { } /// Extension methods for vectors contain `PartialEq` elements. -pub trait ImmutableEqVector { +#[unstable = "may merge with other traits"] +pub trait ImmutablePartialEqSlice { /// Find the first index containing a matching value fn position_elem(&self, t: &T) -> Option; @@ -772,7 +853,8 @@ pub trait ImmutableEqVector { fn ends_with(&self, needle: &[T]) -> bool; } -impl<'a,T:PartialEq> ImmutableEqVector for &'a [T] { +#[unstable = "trait is unstable"] +impl<'a,T:PartialEq> ImmutablePartialEqSlice for &'a [T] { #[inline] fn position_elem(&self, x: &T) -> Option { self.iter().position(|y| *x == *y) @@ -802,23 +884,51 @@ impl<'a,T:PartialEq> ImmutableEqVector for &'a [T] { } /// Extension methods for vectors containing `Ord` elements. -pub trait ImmutableOrdVector { +#[unstable = "may merge with other traits"] +pub trait ImmutableOrdSlice { /** * Binary search a sorted vector for a given element. * * Returns the index of the element or None if not found. */ + #[deprecated = "use binary_search_elem"] fn bsearch_elem(&self, x: &T) -> Option; + + /** + * Binary search a sorted vector 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. + */ + #[unstable] + fn binary_search_elem(&self, x: &T) -> BinarySearchResult; } -impl<'a, T: Ord> ImmutableOrdVector for &'a [T] { +#[unstable = "trait is unstable"] +impl<'a, T: Ord> ImmutableOrdSlice for &'a [T] { + #[deprecated = "use binary_search_elem"] + #[allow(deprecated)] fn bsearch_elem(&self, x: &T) -> Option { self.bsearch(|p| p.cmp(x)) } + + #[unstable] + fn binary_search_elem(&self, x: &T) -> BinarySearchResult { + self.binary_search(|p| p.cmp(x)) + } } /// Trait for &[T] where T is Cloneable -pub trait MutableCloneableVector { +#[unstable = "may merge with other traits"] +pub trait MutableCloneableSlice { + /// 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. + #[deprecated = "renamed to clone_from_slice"] + fn copy_from(self, s: &[T]) -> uint { self.clone_from_slice(s) } + /// 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. @@ -826,7 +936,7 @@ pub trait MutableCloneableVector { /// # Example /// /// ```rust - /// use std::slice::MutableCloneableVector; + /// use std::slice::MutableCloneableSlice; /// /// let mut dst = [0i, 0, 0]; /// let src = [1i, 2]; @@ -838,12 +948,13 @@ pub trait MutableCloneableVector { /// assert!(dst.copy_from(src2) == 3); /// assert!(dst == [3i, 4, 5]); /// ``` - fn copy_from(self, &[T]) -> uint; + fn clone_from_slice(self, &[T]) -> uint; } -impl<'a, T:Clone> MutableCloneableVector for &'a mut [T] { +#[unstable = "trait is unstable"] +impl<'a, T:Clone> MutableCloneableSlice for &'a mut [T] { #[inline] - fn copy_from(self, src: &[T]) -> uint { + fn clone_from_slice(self, src: &[T]) -> uint { for (a, b) in self.mut_iter().zip(src.iter()) { a.clone_from(b); } @@ -859,16 +970,19 @@ impl<'a, T:Clone> MutableCloneableVector for &'a mut [T] { // /// Any vector that can be represented as a slice. -pub trait Vector { +#[unstable = "may merge with other traits"] +pub trait Slice { /// Work with `self` as a slice. fn as_slice<'a>(&'a self) -> &'a [T]; } -impl<'a,T> Vector for &'a [T] { +#[unstable = "trait is unstable"] +impl<'a,T> Slice for &'a [T] { #[inline(always)] fn as_slice<'a>(&'a self) -> &'a [T] { *self } } +#[experimental = "trait is experimental"] impl<'a, T> Collection for &'a [T] { /// Returns the length of a vector #[inline] @@ -877,6 +991,7 @@ impl<'a, T> Collection for &'a [T] { } } +#[unstable = "waiting for DST"] impl<'a, T> Default for &'a [T] { fn default() -> &'a [T] { &[] } } @@ -891,6 +1006,7 @@ impl<'a, T> Default for &'a [T] { // The shared definition of the `Item` and `MutItems` iterators macro_rules! iterator { (struct $name:ident -> $ptr:ty, $elem:ty) => { + #[experimental = "needs review"] impl<'a, T> Iterator<$elem> for $name<'a, T> { #[inline] fn next(&mut self) -> Option<$elem> { @@ -926,6 +1042,7 @@ macro_rules! iterator { } } + #[experimental = "needs review"] impl<'a, T> DoubleEndedIterator<$elem> for $name<'a, T> { #[inline] fn next_back(&mut self) -> Option<$elem> { @@ -953,6 +1070,7 @@ macro_rules! iterator { } /// Immutable slice iterator +#[experimental = "needs review"] pub struct Items<'a, T> { ptr: *const T, end: *const T, @@ -961,12 +1079,15 @@ pub struct Items<'a, T> { iterator!{struct Items -> *const T, &'a T} +#[experimental = "needs review"] impl<'a, T> ExactSize<&'a T> for Items<'a, T> {} +#[experimental = "needs review"] impl<'a, T> Clone for Items<'a, T> { fn clone(&self) -> Items<'a, T> { *self } } +#[experimental = "needs review"] impl<'a, T> RandomAccessIterator<&'a T> for Items<'a, T> { #[inline] fn indexable(&self) -> uint { @@ -992,6 +1113,7 @@ impl<'a, T> RandomAccessIterator<&'a T> for Items<'a, T> { } /// Mutable slice iterator +#[experimental = "needs review"] pub struct MutItems<'a, T> { ptr: *mut T, end: *mut T, @@ -1001,16 +1123,19 @@ pub struct MutItems<'a, T> { iterator!{struct MutItems -> *mut T, &'a mut T} +#[experimental = "needs review"] impl<'a, T> ExactSize<&'a mut T> for MutItems<'a, T> {} /// An iterator over the slices of a vector separated by elements that /// match a predicate function. +#[experimental = "needs review"] pub struct Splits<'a, T> { v: &'a [T], pred: |t: &T|: 'a -> bool, finished: bool } +#[experimental = "needs review"] impl<'a, T> Iterator<&'a [T]> for Splits<'a, T> { #[inline] fn next(&mut self) -> Option<&'a [T]> { @@ -1039,6 +1164,7 @@ impl<'a, T> Iterator<&'a [T]> for Splits<'a, T> { } } +#[experimental = "needs review"] impl<'a, T> DoubleEndedIterator<&'a [T]> for Splits<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a [T]> { @@ -1060,12 +1186,14 @@ impl<'a, T> DoubleEndedIterator<&'a [T]> for Splits<'a, T> { /// An iterator over the subslices of the vector which are separated /// by elements that match `pred`. +#[experimental = "needs review"] pub struct MutSplits<'a, T> { v: &'a mut [T], pred: |t: &T|: 'a -> bool, finished: bool } +#[experimental = "needs review"] impl<'a, T> Iterator<&'a mut [T]> for MutSplits<'a, T> { #[inline] fn next(&mut self) -> Option<&'a mut [T]> { @@ -1102,6 +1230,7 @@ impl<'a, T> Iterator<&'a mut [T]> for MutSplits<'a, T> { } } +#[experimental = "needs review"] impl<'a, T> DoubleEndedIterator<&'a mut [T]> for MutSplits<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a mut [T]> { @@ -1126,12 +1255,14 @@ impl<'a, T> DoubleEndedIterator<&'a mut [T]> for MutSplits<'a, T> { /// An iterator over the slices of a vector separated by elements that /// match a predicate function, splitting at most a fixed number of times. +#[experimental = "needs review"] pub struct SplitsN<'a, T> { iter: Splits<'a, T>, count: uint, invert: bool } +#[experimental = "needs review"] impl<'a, T> Iterator<&'a [T]> for SplitsN<'a, T> { #[inline] fn next(&mut self) -> Option<&'a [T]> { @@ -1161,11 +1292,13 @@ impl<'a, T> Iterator<&'a [T]> for SplitsN<'a, T> { /// An iterator over the (overlapping) slices of length `size` within /// a vector. #[deriving(Clone)] +#[experimental = "needs review"] pub struct Windows<'a, T> { v: &'a [T], size: uint } +#[experimental = "needs review"] impl<'a, T> Iterator<&'a [T]> for Windows<'a, T> { #[inline] fn next(&mut self) -> Option<&'a [T]> { @@ -1195,11 +1328,13 @@ impl<'a, T> Iterator<&'a [T]> for Windows<'a, T> { /// When the vector len is not evenly divided by the chunk size, /// the last slice of the iteration will be the remainder. #[deriving(Clone)] +#[experimental = "needs review"] pub struct Chunks<'a, T> { v: &'a [T], size: uint } +#[experimental = "needs review"] impl<'a, T> Iterator<&'a [T]> for Chunks<'a, T> { #[inline] fn next(&mut self) -> Option<&'a [T]> { @@ -1225,6 +1360,7 @@ impl<'a, T> Iterator<&'a [T]> for Chunks<'a, T> { } } +#[experimental = "needs review"] impl<'a, T> DoubleEndedIterator<&'a [T]> for Chunks<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a [T]> { @@ -1240,6 +1376,7 @@ impl<'a, T> DoubleEndedIterator<&'a [T]> for Chunks<'a, T> { } } +#[experimental = "needs review"] impl<'a, T> RandomAccessIterator<&'a [T]> for Chunks<'a, T> { #[inline] fn indexable(&self) -> uint { @@ -1263,11 +1400,13 @@ impl<'a, T> RandomAccessIterator<&'a [T]> for Chunks<'a, T> { /// An iterator over a vector in (non-overlapping) mutable chunks (`size` elements at a time). When /// the vector len is not evenly divided by the chunk size, the last slice of the iteration will be /// the remainder. +#[experimental = "needs review"] pub struct MutChunks<'a, T> { v: &'a mut [T], chunk_size: uint } +#[experimental = "needs review"] impl<'a, T> Iterator<&'a mut [T]> for MutChunks<'a, T> { #[inline] fn next(&mut self) -> Option<&'a mut [T]> { @@ -1294,6 +1433,7 @@ impl<'a, T> Iterator<&'a mut [T]> for MutChunks<'a, T> { } } +#[experimental = "needs review"] impl<'a, T> DoubleEndedIterator<&'a mut [T]> for MutChunks<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a mut [T]> { @@ -1313,6 +1453,43 @@ impl<'a, T> DoubleEndedIterator<&'a mut [T]> for MutChunks<'a, T> { +/// The result of calling `binary_search`. +/// +/// `Found` means the search succeeded, and the contained value is the +/// index of the matching element. `NotFound` means the search +/// succeeded, and the contained value is an index where a matching +/// value could be inserted while maintaining sort order. +#[deriving(PartialEq, Show)] +#[experimental = "needs review"] +pub enum BinarySearchResult { + /// The index of the found value. + Found(uint), + /// The index where the value should have been found. + NotFound(uint) +} + +#[experimental = "needs review"] +impl BinarySearchResult { + /// Converts a `Found` to `Some`, `NotFound` to `None`. + /// Similar to `Result::ok`. + pub fn found(&self) -> Option { + match *self { + Found(i) => Some(i), + NotFound(_) => None + } + } + + /// Convert a `Found` to `None`, `NotFound` to `Some`. + /// Similar to `Result::err`. + pub fn not_found(&self) -> Option { + match *self { + Found(_) => None, + NotFound(i) => Some(i) + } + } +} + + // // Free functions @@ -1321,19 +1498,21 @@ impl<'a, T> DoubleEndedIterator<&'a mut [T]> for MutChunks<'a, T> { /** * Converts a pointer to A into a slice of length 1 (without copying). */ +#[unstable = "waiting for DST"] pub fn ref_slice<'a, A>(s: &'a A) -> &'a [A] { unsafe { - transmute(Slice { data: s, len: 1 }) + transmute(RawSlice { data: s, len: 1 }) } } /** * Converts a pointer to A into a slice of length 1 (without copying). */ +#[unstable = "waiting for DST"] pub fn mut_ref_slice<'a, A>(s: &'a mut A) -> &'a mut [A] { unsafe { let ptr: *const A = transmute(s); - transmute(Slice { data: ptr, len: 1 }) + transmute(RawSlice { data: ptr, len: 1 }) } } @@ -1345,6 +1524,7 @@ pub fn mut_ref_slice<'a, A>(s: &'a mut A) -> &'a mut [A] { // /// Unsafe operations +#[experimental = "needs review"] pub mod raw { use mem::transmute; use ptr::RawPtr; @@ -1410,10 +1590,11 @@ pub mod raw { } /// Operations on `[u8]`. +#[experimental = "needs review"] pub mod bytes { use collections::Collection; use ptr; - use slice::MutableVector; + use slice::MutableSlice; /// A trait for operations on mutable `[u8]`s. pub trait MutableByteVector { @@ -1447,6 +1628,7 @@ pub mod bytes { // Boilerplate traits // +#[unstable = "waiting for DST"] impl<'a,T:PartialEq> PartialEq for &'a [T] { fn eq(&self, other: & &'a [T]) -> bool { self.len() == other.len() && @@ -1458,19 +1640,23 @@ impl<'a,T:PartialEq> PartialEq for &'a [T] { } } +#[unstable = "waiting for DST"] impl<'a,T:Eq> Eq for &'a [T] {} -impl<'a,T:PartialEq, V: Vector> Equiv for &'a [T] { +#[unstable = "waiting for DST"] +impl<'a,T:PartialEq, V: Slice> Equiv for &'a [T] { #[inline] fn equiv(&self, other: &V) -> bool { self.as_slice() == other.as_slice() } } +#[unstable = "waiting for DST"] impl<'a,T:Ord> Ord for &'a [T] { fn cmp(&self, other: & &'a [T]) -> Ordering { order::cmp(self.iter(), other.iter()) } } +#[unstable = "waiting for DST"] impl<'a, T: PartialOrd> PartialOrd for &'a [T] { #[inline] fn partial_cmp(&self, other: &&'a [T]) -> Option { diff --git a/src/libcore/str.rs b/src/libcore/str.rs index c1166a7621e19..4f7db7b41f38b 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -30,7 +30,7 @@ use iter::range; use num::{CheckedMul, Saturating}; use option::{Option, None, Some}; use raw::Repr; -use slice::ImmutableVector; +use slice::ImmutableSlice; use slice; use uint; @@ -964,7 +964,7 @@ pub mod raw { use collections::Collection; use ptr::RawPtr; use raw::Slice; - use slice::{ImmutableVector}; + use slice::{ImmutableSlice}; use str::{is_utf8, StrSlice}; /// Converts a slice of bytes to a string slice without checking @@ -1147,22 +1147,22 @@ pub trait StrSlice<'a> { /// # Example /// /// ```rust - /// let v: Vec<&str> = "Mary had a little lambda".splitn(' ', 2).collect(); + /// let v: Vec<&str> = "Mary had a little lambda".splitn(2, ' ').collect(); /// assert_eq!(v, vec!["Mary", "had", "a little lambda"]); /// - /// let v: Vec<&str> = "abc1def2ghi".splitn(|c: char| c.is_digit(), 1).collect(); + /// let v: Vec<&str> = "abc1def2ghi".splitn(1, |c: char| c.is_digit()).collect(); /// assert_eq!(v, vec!["abc", "def2ghi"]); /// - /// let v: Vec<&str> = "lionXXtigerXleopard".splitn('X', 2).collect(); + /// let v: Vec<&str> = "lionXXtigerXleopard".splitn(2, 'X').collect(); /// assert_eq!(v, vec!["lion", "", "tigerXleopard"]); /// - /// let v: Vec<&str> = "abcXdef".splitn('X', 0).collect(); + /// let v: Vec<&str> = "abcXdef".splitn(0, 'X').collect(); /// assert_eq!(v, vec!["abcXdef"]); /// - /// let v: Vec<&str> = "".splitn('X', 1).collect(); + /// let v: Vec<&str> = "".splitn(1, 'X').collect(); /// assert_eq!(v, vec![""]); /// ``` - fn splitn(&self, sep: Sep, count: uint) -> CharSplitsN<'a, Sep>; + fn splitn(&self, count: uint, sep: Sep) -> CharSplitsN<'a, Sep>; /// An iterator over substrings of `self`, separated by characters /// matched by `sep`. @@ -1197,16 +1197,16 @@ pub trait StrSlice<'a> { /// # Example /// /// ```rust - /// let v: Vec<&str> = "Mary had a little lamb".rsplitn(' ', 2).collect(); + /// let v: Vec<&str> = "Mary had a little lamb".rsplitn(2, ' ').collect(); /// assert_eq!(v, vec!["lamb", "little", "Mary had a"]); /// - /// let v: Vec<&str> = "abc1def2ghi".rsplitn(|c: char| c.is_digit(), 1).collect(); + /// let v: Vec<&str> = "abc1def2ghi".rsplitn(1, |c: char| c.is_digit()).collect(); /// assert_eq!(v, vec!["ghi", "abc1def"]); /// - /// let v: Vec<&str> = "lionXXtigerXleopard".rsplitn('X', 2).collect(); + /// let v: Vec<&str> = "lionXXtigerXleopard".rsplitn(2, 'X').collect(); /// assert_eq!(v, vec!["leopard", "tiger", "lionX"]); /// ``` - fn rsplitn(&self, sep: Sep, count: uint) -> CharSplitsN<'a, Sep>; + fn rsplitn(&self, count: uint, sep: Sep) -> CharSplitsN<'a, Sep>; /// An iterator over the start and end indices of the disjoint /// matches of `sep` within `self`. @@ -1697,7 +1697,7 @@ impl<'a> StrSlice<'a> for &'a str { } #[inline] - fn splitn(&self, sep: Sep, count: uint) + fn splitn(&self, count: uint, sep: Sep) -> CharSplitsN<'a, Sep> { CharSplitsN { iter: self.split(sep), @@ -1716,7 +1716,7 @@ impl<'a> StrSlice<'a> for &'a str { } #[inline] - fn rsplitn(&self, sep: Sep, count: uint) + fn rsplitn(&self, count: uint, sep: Sep) -> CharSplitsN<'a, Sep> { CharSplitsN { iter: self.split(sep), diff --git a/src/libcoretest/lib.rs b/src/libcoretest/lib.rs index 0b8ae09c9a346..3864321586ca6 100644 --- a/src/libcoretest/lib.rs +++ b/src/libcoretest/lib.rs @@ -28,4 +28,5 @@ mod option; mod ptr; mod raw; mod result; +mod slice; mod tuple; diff --git a/src/libcoretest/slice.rs b/src/libcoretest/slice.rs new file mode 100644 index 0000000000000..1288756dea4a5 --- /dev/null +++ b/src/libcoretest/slice.rs @@ -0,0 +1,35 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::slice::{Found, NotFound}; + +#[test] +fn binary_search_not_found() { + let b = [1i, 2, 4, 6, 8, 9]; + assert!(b.binary_search(|v| v.cmp(&6)) == Found(3)); + let b = [1i, 2, 4, 6, 8, 9]; + assert!(b.binary_search(|v| v.cmp(&5)) == NotFound(3)); + let b = [1i, 2, 4, 6, 7, 8, 9]; + assert!(b.binary_search(|v| v.cmp(&6)) == Found(3)); + let b = [1i, 2, 4, 6, 7, 8, 9]; + assert!(b.binary_search(|v| v.cmp(&5)) == NotFound(3)); + let b = [1i, 2, 4, 6, 8, 9]; + assert!(b.binary_search(|v| v.cmp(&8)) == Found(4)); + let b = [1i, 2, 4, 6, 8, 9]; + assert!(b.binary_search(|v| v.cmp(&7)) == NotFound(4)); + let b = [1i, 2, 4, 6, 7, 8, 9]; + assert!(b.binary_search(|v| v.cmp(&8)) == Found(5)); + let b = [1i, 2, 4, 5, 6, 8, 9]; + assert!(b.binary_search(|v| v.cmp(&7)) == NotFound(5)); + let b = [1i, 2, 4, 5, 6, 8, 9]; + assert!(b.binary_search(|v| v.cmp(&0)) == NotFound(0)); + let b = [1i, 2, 4, 5, 6, 8]; + assert!(b.binary_search(|v| v.cmp(&9)) == NotFound(6)); +} diff --git a/src/libgraphviz/maybe_owned_vec.rs b/src/libgraphviz/maybe_owned_vec.rs index 9e52af72138bb..987f214b153e0 100644 --- a/src/libgraphviz/maybe_owned_vec.rs +++ b/src/libgraphviz/maybe_owned_vec.rs @@ -84,7 +84,7 @@ impl<'a, T: Ord> Ord for MaybeOwnedVector<'a, T> { } } -impl<'a, T: PartialEq, V: Vector> Equiv for MaybeOwnedVector<'a, T> { +impl<'a, T: PartialEq, V: Slice> Equiv for MaybeOwnedVector<'a, T> { fn equiv(&self, other: &V) -> bool { self.as_slice() == other.as_slice() } @@ -99,7 +99,7 @@ impl<'a, T: PartialEq, V: Vector> Equiv for MaybeOwnedVector<'a, T> { // In any case, with `Vector` in place, the client can just use // `as_slice` if they prefer that over `match`. -impl<'b,T> slice::Vector for MaybeOwnedVector<'b,T> { +impl<'b,T> Slice for MaybeOwnedVector<'b,T> { fn as_slice<'a>(&'a self) -> &'a [T] { match self { &Growable(ref v) => v.as_slice(), diff --git a/src/libnum/rational.rs b/src/libnum/rational.rs index e0f6b4fb9af66..f3e4b0b21adf8 100644 --- a/src/libnum/rational.rs +++ b/src/libnum/rational.rs @@ -341,7 +341,7 @@ impl FromStr for Ratio { /// Parses `numer/denom` or just `numer`. fn from_str(s: &str) -> Option> { - let mut split = s.splitn('/', 1); + let mut split = s.splitn(1, '/'); let num = split.next().and_then(|n| FromStr::from_str(n)); let den = split.next().or(Some("1")).and_then(|d| FromStr::from_str(d)); @@ -357,7 +357,7 @@ impl FromStrRadix for Ratio { /// Parses `numer/denom` where the numbers are in base `radix`. fn from_str_radix(s: &str, radix: uint) -> Option> { - let split: Vec<&str> = s.splitn('/', 1).collect(); + let split: Vec<&str> = s.splitn(1, '/').collect(); if split.len() < 2 { None } else { diff --git a/src/librand/isaac.rs b/src/librand/isaac.rs index 134e7af507010..2fbfa6d6e85a0 100644 --- a/src/librand/isaac.rs +++ b/src/librand/isaac.rs @@ -348,7 +348,7 @@ impl Isaac64Rng { static MP_VEC: [(uint, uint), .. 2] = [(0,MIDPOINT), (MIDPOINT, 0)]; macro_rules! ind ( ($x:expr) => { - *self.mem.unsafe_ref(($x as uint >> 3) & (RAND_SIZE_64 - 1)) + *self.mem.unsafe_get(($x as uint >> 3) & (RAND_SIZE_64 - 1)) } ); @@ -362,8 +362,8 @@ impl Isaac64Rng { let mix = if $j == 0 {!mix} else {mix}; unsafe { - let x = *self.mem.unsafe_ref(base + mr_offset); - a = mix + *self.mem.unsafe_ref(base + m2_offset); + let x = *self.mem.unsafe_get(base + mr_offset); + a = mix + *self.mem.unsafe_get(base + m2_offset); let y = ind!(x) + a + b; self.mem.unsafe_set(base + mr_offset, y); @@ -379,8 +379,8 @@ impl Isaac64Rng { let mix = if $j == 0 {!mix} else {mix}; unsafe { - let x = *self.mem.unsafe_ref(base + mr_offset); - a = mix + *self.mem.unsafe_ref(base + m2_offset); + let x = *self.mem.unsafe_get(base + mr_offset); + a = mix + *self.mem.unsafe_get(base + m2_offset); let y = ind!(x) + a + b; self.mem.unsafe_set(base + mr_offset, y); @@ -416,7 +416,7 @@ impl Rng for Isaac64Rng { self.isaac64(); } self.cnt -= 1; - unsafe { *self.rsl.unsafe_ref(self.cnt) } + unsafe { *self.rsl.unsafe_get(self.cnt) } } } diff --git a/src/libregex/parse.rs b/src/libregex/parse.rs index a1fd62cecbed9..13b094a2cf2e6 100644 --- a/src/libregex/parse.rs +++ b/src/libregex/parse.rs @@ -13,6 +13,7 @@ use std::cmp; use std::fmt; use std::iter; use std::num; +use std::slice; /// Static data containing Unicode ranges for general categories and scripts. use unicode::regex::{UNICODE_CLASSES, PERLD, PERLS, PERLW}; @@ -518,7 +519,7 @@ impl<'a> Parser<'a> { min = try!(self.parse_uint(inner.as_slice())); max = Some(min); } else { - let pieces: Vec<&str> = inner.as_slice().splitn(',', 1).collect(); + let pieces: Vec<&str> = inner.as_slice().splitn(1, ',').collect(); let (smin, smax) = (pieces[0], pieces[1]); if smin.len() == 0 { return self.err("Max repetitions cannot be specified \ @@ -1017,9 +1018,9 @@ fn is_valid_cap(c: char) -> bool { } fn find_class(classes: NamedClasses, name: &str) -> Option> { - match classes.bsearch(|&(s, _)| s.cmp(&name)) { - Some(i) => Some(Vec::from_slice(classes[i].val1())), - None => None, + match classes.binary_search(|&(s, _)| s.cmp(&name)) { + slice::Found(i) => Some(Vec::from_slice(classes[i].val1())), + slice::NotFound(_) => None, } } diff --git a/src/libregex/vm.rs b/src/libregex/vm.rs index b37000df02dbe..507a7641f2201 100644 --- a/src/libregex/vm.rs +++ b/src/libregex/vm.rs @@ -35,7 +35,7 @@ use std::cmp; use std::mem; -use std::slice::MutableVector; +use std::slice::MutableSlice; use compile::{ Program, Match, OneChar, CharClass, Any, EmptyBegin, EmptyEnd, EmptyWordBoundary, @@ -222,8 +222,8 @@ impl<'r, 't> Nfa<'r, 't> { let negate = flags & FLAG_NEGATED > 0; let casei = flags & FLAG_NOCASE > 0; let found = ranges.as_slice(); - let found = found.bsearch(|&rc| class_cmp(casei, c, rc)); - let found = found.is_some(); + let found = found.binary_search(|&rc| class_cmp(casei, c, rc)) + .found().is_some(); if found ^ negate { self.add(nlist, pc+1, caps); } @@ -513,7 +513,7 @@ pub fn is_word(c: Option) -> bool { // Try the common ASCII case before invoking binary search. match c { '_' | '0' .. '9' | 'a' .. 'z' | 'A' .. 'Z' => true, - _ => PERLW.bsearch(|&(start, end)| { + _ => PERLW.binary_search(|&(start, end)| { if c >= start && c <= end { Equal } else if start > c { @@ -521,7 +521,7 @@ pub fn is_word(c: Option) -> bool { } else { Less } - }).is_some() + }).found().is_some() } } diff --git a/src/librlibc/lib.rs b/src/librlibc/lib.rs index c7295125f42f7..706b5c3325576 100644 --- a/src/librlibc/lib.rs +++ b/src/librlibc/lib.rs @@ -112,7 +112,7 @@ mod test { use core::iter::Iterator; use core::collections::Collection; use core::str::StrSlice; - use core::slice::{MutableVector, ImmutableVector}; + use core::slice::{MutableSlice, ImmutableSlice}; use super::{memcmp, memset, memcpy, memmove}; diff --git a/src/librustc/driver/config.rs b/src/librustc/driver/config.rs index f4309d9e51b56..826579b62fcba 100644 --- a/src/librustc/driver/config.rs +++ b/src/librustc/driver/config.rs @@ -353,7 +353,7 @@ pub fn build_codegen_options(matches: &getopts::Matches) -> CodegenOptions { let mut cg = basic_codegen_options(); for option in matches.opt_strs("C").move_iter() { - let mut iter = option.as_slice().splitn('=', 1); + let mut iter = option.as_slice().splitn(1, '='); let key = iter.next().unwrap(); let value = iter.next(); let option_to_lookup = key.replace("-", "_"); @@ -750,7 +750,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { let mut externs = HashMap::new(); for arg in matches.opt_strs("extern").iter() { - let mut parts = arg.as_slice().splitn('=', 1); + let mut parts = arg.as_slice().splitn(1, '='); let name = match parts.next() { Some(s) => s, None => early_error("--extern value must not be empty"), diff --git a/src/librustc/driver/mod.rs b/src/librustc/driver/mod.rs index 05762aa3db276..dc600e0da3ec0 100644 --- a/src/librustc/driver/mod.rs +++ b/src/librustc/driver/mod.rs @@ -356,7 +356,7 @@ pub enum PpMode { } fn parse_pretty(sess: &Session, name: &str) -> (PpMode, Option) { - let mut split = name.splitn('=', 1); + let mut split = name.splitn(1, '='); let first = split.next().unwrap(); let opt_second = split.next(); let first = match first { diff --git a/src/librustc/front/test.rs b/src/librustc/front/test.rs index 14cda7d62c35d..ceb7dcc54560c 100644 --- a/src/librustc/front/test.rs +++ b/src/librustc/front/test.rs @@ -379,7 +379,7 @@ fn mk_test_module(cx: &TestCtxt, reexport_test_harness_main: &Option Result { let mut externs = HashMap::new(); for arg in matches.opt_strs("extern").iter() { - let mut parts = arg.as_slice().splitn('=', 1); + let mut parts = arg.as_slice().splitn(1, '='); let name = match parts.next() { Some(s) => s, None => { diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index e8352dcd40cdc..e5f42bd65a300 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -19,7 +19,7 @@ use fmt; use iter::Iterator; use mem; use option::{Option, Some, None}; -use slice::{ImmutableVector, MutableVector, Vector}; +use slice::{ImmutableSlice, MutableSlice, Slice}; use str::{Str, StrSlice}; use str; use string::String; diff --git a/src/libstd/c_vec.rs b/src/libstd/c_vec.rs index 80fe05fcea5cd..5f52c0ada5d62 100644 --- a/src/libstd/c_vec.rs +++ b/src/libstd/c_vec.rs @@ -43,7 +43,7 @@ use option::{Option, Some, None}; use ptr::RawPtr; use ptr; use raw; -use slice::Vector; +use slice::Slice; /// The type representing a foreign chunk of memory pub struct CVec { @@ -145,7 +145,7 @@ impl CVec { } } -impl Vector for CVec { +impl Slice for CVec { /// View the stored data as a slice. fn as_slice<'a>(&'a self) -> &'a [T] { unsafe { diff --git a/src/libstd/collections/hashmap.rs b/src/libstd/collections/hashmap.rs index 2de9db1cc93e3..b8f8bd41a2d9d 100644 --- a/src/libstd/collections/hashmap.rs +++ b/src/libstd/collections/hashmap.rs @@ -2743,7 +2743,7 @@ mod test_set { use prelude::*; use super::HashSet; - use slice::ImmutableEqVector; + use slice::ImmutablePartialEqSlice; use collections::Collection; #[test] diff --git a/src/libstd/dynamic_lib.rs b/src/libstd/dynamic_lib.rs index 1ac37458e2493..766f92292b187 100644 --- a/src/libstd/dynamic_lib.rs +++ b/src/libstd/dynamic_lib.rs @@ -29,7 +29,7 @@ use option::*; use os; use path::{Path,GenericPath}; use result::*; -use slice::{Vector,ImmutableVector}; +use slice::{Slice,ImmutableSlice}; use str; use string::String; use vec::Vec; diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index 71ec524211824..a9b0b33c59ad9 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -19,7 +19,7 @@ use iter::ExactSize; use ops::Drop; use option::{Some, None, Option}; use result::{Ok, Err}; -use slice::{ImmutableVector, MutableVector}; +use slice::{ImmutableSlice, MutableSlice}; use slice; use vec::Vec; diff --git a/src/libstd/io/comm_adapters.rs b/src/libstd/io/comm_adapters.rs index cd5887b7add00..53b5fbe3894ed 100644 --- a/src/libstd/io/comm_adapters.rs +++ b/src/libstd/io/comm_adapters.rs @@ -15,7 +15,7 @@ use comm::{Sender, Receiver}; use io; use option::{None, Option, Some}; use result::{Ok, Err}; -use slice::{bytes, MutableVector, ImmutableVector}; +use slice::{bytes, MutableSlice, ImmutableSlice}; use str::StrSlice; use super::{Reader, Writer, IoResult}; use vec::Vec; diff --git a/src/libstd/io/extensions.rs b/src/libstd/io/extensions.rs index 5215aec5dfbfa..12caa7158658e 100644 --- a/src/libstd/io/extensions.rs +++ b/src/libstd/io/extensions.rs @@ -21,7 +21,7 @@ use option::{Option, Some, None}; use result::{Ok, Err}; use io; use io::{IoError, IoResult, Reader}; -use slice::{ImmutableVector, Vector}; +use slice::{ImmutableSlice, Slice}; use ptr::RawPtr; /// An iterator that reads a single byte on each iteration, @@ -153,7 +153,7 @@ pub fn u64_to_be_bytes(n: u64, size: uint, f: |v: &[u8]| -> T) -> T { pub fn u64_from_be_bytes(data: &[u8], start: uint, size: uint) -> u64 { use ptr::{copy_nonoverlapping_memory}; use mem::from_be64; - use slice::MutableVector; + use slice::MutableSlice; assert!(size <= 8u); diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index 7335511ed857e..f95f41509a0f5 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -70,7 +70,7 @@ use path; use result::{Err, Ok}; use rt::rtio::LocalIo; use rt::rtio; -use slice::ImmutableVector; +use slice::ImmutableSlice; use string::String; use vec::Vec; diff --git a/src/libstd/io/mem.rs b/src/libstd/io/mem.rs index 8879f7e25063c..ea9d08171e6ce 100644 --- a/src/libstd/io/mem.rs +++ b/src/libstd/io/mem.rs @@ -19,7 +19,7 @@ use result::{Err, Ok}; use io; use io::{Reader, Writer, Seek, Buffer, IoError, SeekStyle, IoResult}; use slice; -use slice::{Vector, ImmutableVector, MutableVector}; +use slice::{Slice, ImmutableSlice, MutableSlice}; use vec::Vec; static BUF_CAPACITY: uint = 128; diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index d098f9a647914..c95dd8618ed10 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -235,7 +235,7 @@ use os; use boxed::Box; use result::{Ok, Err, Result}; use rt::rtio; -use slice::{Vector, MutableVector, ImmutableVector}; +use slice::{Slice, MutableSlice, ImmutableSlice}; use str::{Str, StrSlice}; use str; use string::String; diff --git a/src/libstd/io/net/ip.rs b/src/libstd/io/net/ip.rs index 0f864c7be5e27..ed76cdc276ba6 100644 --- a/src/libstd/io/net/ip.rs +++ b/src/libstd/io/net/ip.rs @@ -21,7 +21,7 @@ use from_str::FromStr; use iter::Iterator; use option::{Option, None, Some}; use str::StrSlice; -use slice::{MutableCloneableVector, ImmutableVector, MutableVector}; +use slice::{MutableCloneableSlice, ImmutableSlice, MutableSlice}; pub type Port = u16; diff --git a/src/libstd/io/net/tcp.rs b/src/libstd/io/net/tcp.rs index 5c91c48c55d5b..7055b9d7a4738 100644 --- a/src/libstd/io/net/tcp.rs +++ b/src/libstd/io/net/tcp.rs @@ -21,7 +21,7 @@ use clone::Clone; use collections::MutableSeq; use io::IoResult; use iter::Iterator; -use slice::ImmutableVector; +use slice::ImmutableSlice; use result::{Ok,Err}; use io::net::addrinfo::get_host_addresses; use io::net::ip::SocketAddr; diff --git a/src/libstd/io/signal.rs b/src/libstd/io/signal.rs index 10739c70143cd..1d882bdc0ad9e 100644 --- a/src/libstd/io/signal.rs +++ b/src/libstd/io/signal.rs @@ -30,7 +30,7 @@ use option::{Some, None}; use boxed::Box; use result::{Ok, Err}; use rt::rtio::{IoFactory, LocalIo, RtioSignal, Callback}; -use slice::ImmutableVector; +use slice::ImmutableSlice; use vec::Vec; /// Signals that can be sent and received diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 5b33c3671b488..fea161c426a2e 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -41,7 +41,7 @@ use rt; use rt::local::Local; use rt::task::Task; use rt::rtio::{DontClose, IoFactory, LocalIo, RtioFileStream, RtioTTY}; -use slice::ImmutableVector; +use slice::ImmutableSlice; use str::StrSlice; use uint; diff --git a/src/libstd/num/i16.rs b/src/libstd/num/i16.rs index 9b97513935c80..f5b2f31a127d6 100644 --- a/src/libstd/num/i16.rs +++ b/src/libstd/num/i16.rs @@ -17,7 +17,7 @@ use from_str::FromStr; use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; -use slice::ImmutableVector; +use slice::ImmutableSlice; use string::String; pub use core::i16::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/i32.rs b/src/libstd/num/i32.rs index 03dcbb0f6d671..623a10725c826 100644 --- a/src/libstd/num/i32.rs +++ b/src/libstd/num/i32.rs @@ -17,7 +17,7 @@ use from_str::FromStr; use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; -use slice::ImmutableVector; +use slice::ImmutableSlice; use string::String; pub use core::i32::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/i64.rs b/src/libstd/num/i64.rs index 347b5b4b93ce7..ffb1307908c90 100644 --- a/src/libstd/num/i64.rs +++ b/src/libstd/num/i64.rs @@ -17,7 +17,7 @@ use from_str::FromStr; use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; -use slice::ImmutableVector; +use slice::ImmutableSlice; use string::String; pub use core::i64::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/i8.rs b/src/libstd/num/i8.rs index fd6f96a0f97be..4fbb7381238dc 100644 --- a/src/libstd/num/i8.rs +++ b/src/libstd/num/i8.rs @@ -17,7 +17,7 @@ use from_str::FromStr; use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; -use slice::ImmutableVector; +use slice::ImmutableSlice; use string::String; pub use core::i8::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/int.rs b/src/libstd/num/int.rs index 1888d6a519e39..7821306f5fc3d 100644 --- a/src/libstd/num/int.rs +++ b/src/libstd/num/int.rs @@ -17,7 +17,7 @@ use from_str::FromStr; use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; -use slice::ImmutableVector; +use slice::ImmutableSlice; use string::String; pub use core::int::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index 37378518dc8e1..407c8ea61d914 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -20,7 +20,7 @@ use num::{Float, FPNaN, FPInfinite, ToPrimitive}; use num; use ops::{Add, Sub, Mul, Div, Rem, Neg}; use option::{None, Option, Some}; -use slice::{ImmutableVector, MutableVector}; +use slice::{ImmutableSlice, MutableSlice}; use std::cmp::{PartialOrd, PartialEq}; use str::StrSlice; use string::String; diff --git a/src/libstd/num/u16.rs b/src/libstd/num/u16.rs index 727d756106276..0f00f99e980a2 100644 --- a/src/libstd/num/u16.rs +++ b/src/libstd/num/u16.rs @@ -17,7 +17,7 @@ use from_str::FromStr; use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; -use slice::ImmutableVector; +use slice::ImmutableSlice; use string::String; pub use core::u16::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/u32.rs b/src/libstd/num/u32.rs index d18bfdf9fbac0..e6c6bc377b7aa 100644 --- a/src/libstd/num/u32.rs +++ b/src/libstd/num/u32.rs @@ -17,7 +17,7 @@ use from_str::FromStr; use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; -use slice::ImmutableVector; +use slice::ImmutableSlice; use string::String; pub use core::u32::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/u64.rs b/src/libstd/num/u64.rs index 53e88a96f332d..7eb9e1a082fe8 100644 --- a/src/libstd/num/u64.rs +++ b/src/libstd/num/u64.rs @@ -17,7 +17,7 @@ use from_str::FromStr; use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; -use slice::ImmutableVector; +use slice::ImmutableSlice; use string::String; pub use core::u64::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/u8.rs b/src/libstd/num/u8.rs index e6cbd14bf417d..300dd3bcc01a4 100644 --- a/src/libstd/num/u8.rs +++ b/src/libstd/num/u8.rs @@ -17,7 +17,7 @@ use from_str::FromStr; use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; -use slice::ImmutableVector; +use slice::ImmutableSlice; use string::String; pub use core::u8::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/uint.rs b/src/libstd/num/uint.rs index 41c4caf4006f1..0adc22e321406 100644 --- a/src/libstd/num/uint.rs +++ b/src/libstd/num/uint.rs @@ -17,7 +17,7 @@ use from_str::FromStr; use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; -use slice::ImmutableVector; +use slice::ImmutableSlice; use string::String; pub use core::uint::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 85445e4913935..6a00368f9a21e 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -45,7 +45,7 @@ use path::{Path, GenericPath, BytesContainer}; use ptr::RawPtr; use ptr; use result::{Err, Ok, Result}; -use slice::{Vector, ImmutableVector, MutableVector, ImmutableEqVector}; +use slice::{Slice, ImmutableSlice, MutableSlice, ImmutablePartialEqSlice}; use str::{Str, StrSlice, StrAllocating}; use string::String; use sync::atomic::{AtomicInt, INIT_ATOMIC_INT, SeqCst}; @@ -145,7 +145,7 @@ pub mod win32 { use option::{None, Option}; use option; use os::TMPBUF_SZ; - use slice::{MutableVector, ImmutableVector}; + use slice::{MutableSlice, ImmutableSlice}; use string::String; use str::StrSlice; use vec::Vec; diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index d290a5f8c63c7..d24c2e2266d4c 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -74,8 +74,8 @@ use option::{Option, None, Some}; use str; use str::{MaybeOwned, Str, StrSlice}; use string::String; -use slice::Vector; -use slice::{ImmutableEqVector, ImmutableVector}; +use slice::Slice; +use slice::{ImmutablePartialEqSlice, ImmutableSlice}; use vec::Vec; /// Typedef for POSIX file paths. diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 9a4bc11f5c03a..0a7817c3e0047 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -21,8 +21,8 @@ use iter::{DoubleEndedIterator, AdditiveIterator, Extendable, Iterator, Map}; use option::{Option, None, Some}; use str::Str; use str; -use slice::{CloneableVector, Splits, Vector, VectorVector, - ImmutableEqVector, ImmutableVector}; +use slice::{CloneableVector, Splits, Slice, VectorVector, + ImmutablePartialEqSlice, ImmutableSlice}; use vec::Vec; use super::{BytesContainer, GenericPath, GenericPathUnsafe}; @@ -367,7 +367,7 @@ impl Path { /// Returns a normalized byte vector representation of a path, by removing all empty /// components, and unnecessary . and .. components. - fn normalize+CloneableVector>(v: V) -> Vec { + fn normalize+CloneableVector>(v: V) -> Vec { // borrowck is being very picky let val = { let is_abs = !v.as_slice().is_empty() && v.as_slice()[0] == SEP_BYTE; diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index c3a217bf940f3..8402d751bf2c8 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -23,7 +23,7 @@ use io::Writer; use iter::{AdditiveIterator, DoubleEndedIterator, Extendable, Iterator, Map}; use mem; use option::{Option, Some, None}; -use slice::{Vector, ImmutableVector}; +use slice::{Slice, ImmutableSlice}; use str::{CharSplits, Str, StrAllocating, StrVector, StrSlice}; use string::String; use unicode::char::UnicodeChar; diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index aa407ce8e0ccb..eb6dcc1f1a586 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -83,11 +83,11 @@ #[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::{MutableCloneableVector, MutableOrdVector}; -#[doc(no_inline)] pub use slice::{ImmutableVector, MutableVector}; -#[doc(no_inline)] pub use slice::{ImmutableEqVector, ImmutableOrdVector}; -#[doc(no_inline)] pub use slice::{Vector, VectorVector}; -#[doc(no_inline)] pub use slice::MutableVectorAllocating; +#[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::{Slice, VectorVector}; +#[doc(no_inline)] pub use slice::MutableSliceAllocating; #[doc(no_inline)] pub use string::String; #[doc(no_inline)] pub use vec::Vec; diff --git a/src/libstd/rand/os.rs b/src/libstd/rand/os.rs index ffe8e539ffba1..2be4129883f74 100644 --- a/src/libstd/rand/os.rs +++ b/src/libstd/rand/os.rs @@ -70,7 +70,7 @@ mod imp { use rand::Rng; use result::{Ok}; use self::libc::{c_int, size_t}; - use slice::MutableVector; + use slice::MutableSlice; /// A random number generator that retrieves randomness straight from /// the operating system. Platform sources: @@ -138,7 +138,7 @@ mod imp { use rt::stack; use self::libc::{DWORD, BYTE, LPCSTR, BOOL}; use self::libc::types::os::arch::extra::{LONG_PTR}; - use slice::MutableVector; + use slice::MutableSlice; type HCRYPTPROV = LONG_PTR; diff --git a/src/libstd/rt/backtrace.rs b/src/libstd/rt/backtrace.rs index b86937e421301..a4491b2ab1d46 100644 --- a/src/libstd/rt/backtrace.rs +++ b/src/libstd/rt/backtrace.rs @@ -258,7 +258,7 @@ mod imp { pub fn write(w: &mut Writer) -> IoResult<()> { use iter::{Iterator, range}; use result; - use slice::{MutableVector}; + use slice::{MutableSlice}; extern { fn backtrace(buf: *mut *mut libc::c_void, @@ -398,7 +398,7 @@ mod imp { use path::GenericPath; use ptr::RawPtr; use ptr; - use slice::{ImmutableVector, MutableVector}; + use slice::{ImmutableSlice, MutableSlice}; //////////////////////////////////////////////////////////////////////// // libbacktrace.h API @@ -670,7 +670,7 @@ mod imp { use path::Path; use result::{Ok, Err}; use rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT}; - use slice::ImmutableVector; + use slice::ImmutableSlice; use str::StrSlice; use dynamic_lib::DynamicLibrary; diff --git a/src/libsyntax/crateid.rs b/src/libsyntax/crateid.rs index b9298cca4f87d..67605360a48cb 100644 --- a/src/libsyntax/crateid.rs +++ b/src/libsyntax/crateid.rs @@ -51,7 +51,7 @@ impl fmt::Show for CrateId { impl FromStr for CrateId { fn from_str(s: &str) -> Option { - let pieces: Vec<&str> = s.splitn('#', 1).collect(); + let pieces: Vec<&str> = s.splitn(1, '#').collect(); let path = pieces.get(0).to_string(); if path.as_slice().starts_with("/") || path.as_slice().ends_with("/") || @@ -60,7 +60,7 @@ impl FromStr for CrateId { } let path_pieces: Vec<&str> = path.as_slice() - .rsplitn('/', 1) + .rsplitn(1, '/') .collect(); let inferred_name = *path_pieces.get(0); @@ -68,7 +68,7 @@ impl FromStr for CrateId { (inferred_name.to_string(), None) } else { let hash_pieces: Vec<&str> = pieces.get(1) - .splitn(':', 1) + .splitn(1, ':') .collect(); let (hash_name, hash_version) = if hash_pieces.len() == 1 { ("", *hash_pieces.get(0)) diff --git a/src/libunicode/normalize.rs b/src/libunicode/normalize.rs index ec31181e8a748..a60e95c38272b 100644 --- a/src/libunicode/normalize.rs +++ b/src/libunicode/normalize.rs @@ -15,20 +15,21 @@ use core::cmp::{Equal, Less, Greater}; use core::option::{Option, Some, None}; -use core::slice::ImmutableVector; +use core::slice; +use core::slice::ImmutableSlice; use tables::normalization::{canonical_table, compatibility_table, composition_table}; fn bsearch_table(c: char, r: &'static [(char, &'static [T])]) -> Option<&'static [T]> { - match r.bsearch(|&(val, _)| { + match r.binary_search(|&(val, _)| { if c == val { Equal } else if val < c { Less } else { Greater } }) { - Some(idx) => { + slice::Found(idx) => { let (_, result) = r[idx]; Some(result) } - None => None + slice::NotFound(_) => None } } @@ -82,16 +83,16 @@ pub fn compose(a: char, b: char) -> Option { match bsearch_table(a, composition_table) { None => None, Some(candidates) => { - match candidates.bsearch(|&(val, _)| { + match candidates.binary_search(|&(val, _)| { if b == val { Equal } else if val < b { Less } else { Greater } }) { - Some(idx) => { + slice::Found(idx) => { let (_, result) = candidates[idx]; Some(result) } - None => None + slice::NotFound(_) => None } } } diff --git a/src/libunicode/tables.rs b/src/libunicode/tables.rs index 4332fc596c997..d6010cd8d7bfb 100644 --- a/src/libunicode/tables.rs +++ b/src/libunicode/tables.rs @@ -14,13 +14,12 @@ fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool { use core::cmp::{Equal, Less, Greater}; - use core::slice::ImmutableVector; - use core::option::None; - r.bsearch(|&(lo,hi)| { + use core::slice::ImmutableSlice; + r.binary_search(|&(lo,hi)| { if lo <= c && c <= hi { Equal } else if hi < c { Less } else { Greater } - }) != None + }).found().is_some() } pub mod general_category { @@ -6228,19 +6227,19 @@ pub mod normalization { fn bsearch_range_value_table(c: char, r: &'static [(char, char, u8)]) -> u8 { - use core::option::{Some, None}; use core::cmp::{Equal, Less, Greater}; - use core::slice::ImmutableVector; - match r.bsearch(|&(lo, hi, _)| { + use core::slice::ImmutableSlice; + use core::slice; + match r.binary_search(|&(lo, hi, _)| { if lo <= c && c <= hi { Equal } else if hi < c { Less } else { Greater } }) { - Some(idx) => { + slice::Found(idx) => { let (_, _, result) = r[idx]; result } - None => 0 + slice::NotFound(_) => 0 } } @@ -6354,9 +6353,10 @@ pub mod normalization { pub mod conversions { use core::cmp::{Equal, Less, Greater}; - use core::slice::ImmutableVector; + use core::slice::ImmutableSlice; use core::tuple::Tuple2; use core::option::{Option, Some, None}; + use core::slice; pub fn to_lower(c: char) -> char { match bsearch_case_table(c, LuLl_table) { @@ -6373,11 +6373,14 @@ pub mod conversions { } fn bsearch_case_table(c: char, table: &'static [(char, char)]) -> Option { - table.bsearch(|&(key, _)| { + match table.binary_search(|&(key, _)| { if c == key { Equal } else if key < c { Less } else { Greater } - }) + }) { + slice::Found(i) => Some(i), + slice::NotFound(_) => None, + } } static LuLl_table: &'static [(char, char)] = &[ @@ -6915,20 +6918,21 @@ pub mod conversions { pub mod charwidth { use core::option::{Option, Some, None}; - use core::slice::ImmutableVector; + use core::slice::ImmutableSlice; + use core::slice; fn bsearch_range_value_table(c: char, is_cjk: bool, r: &'static [(char, char, u8, u8)]) -> u8 { use core::cmp::{Equal, Less, Greater}; - match r.bsearch(|&(lo, hi, _, _)| { + match r.binary_search(|&(lo, hi, _, _)| { if lo <= c && c <= hi { Equal } else if hi < c { Less } else { Greater } }) { - Some(idx) => { + slice::Found(idx) => { let (_, _, r_ncjk, r_cjk) = r[idx]; if is_cjk { r_cjk } else { r_ncjk } } - None => 1 + slice::NotFound(_) => 1 } } @@ -7112,8 +7116,8 @@ pub mod charwidth { } pub mod grapheme { - use core::option::{Some, None}; - use core::slice::ImmutableVector; + use core::slice::ImmutableSlice; + use core::slice; #[allow(non_camel_case_types)] #[deriving(Clone)] @@ -7132,16 +7136,16 @@ pub mod grapheme { fn bsearch_range_value_table(c: char, r: &'static [(char, char, GraphemeCat)]) -> GraphemeCat { use core::cmp::{Equal, Less, Greater}; - match r.bsearch(|&(lo, hi, _)| { + match r.binary_search(|&(lo, hi, _)| { if lo <= c && c <= hi { Equal } else if hi < c { Less } else { Greater } }) { - Some(idx) => { + slice::Found(idx) => { let (_, _, cat) = r[idx]; cat } - None => GC_Any + slice::NotFound(_) => GC_Any } } diff --git a/src/liburl/lib.rs b/src/liburl/lib.rs index 8c35424d394f4..9ced6cb62af00 100644 --- a/src/liburl/lib.rs +++ b/src/liburl/lib.rs @@ -396,7 +396,7 @@ pub fn decode_form_urlencoded(s: &[u8]) } fn split_char_first(s: &str, c: char) -> (&str, &str) { - let mut iter = s.splitn(c, 1); + let mut iter = s.splitn(1, c); match (iter.next(), iter.next()) { (Some(a), Some(b)) => (a, b),