From 59976942eacd26c0cc37247c3ac0c78b97edc6ea Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Wed, 24 Sep 2014 23:41:09 +1200 Subject: Use slice syntax instead of slice_to, etc. --- src/libstd/path/mod.rs | 8 ++++---- src/libstd/path/posix.rs | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) (limited to 'src/libstd/path') diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index 16552daae36..63c81695aff 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -357,7 +357,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { match name.rposition_elem(&dot) { None | Some(0) => name, Some(1) if name == b".." => name, - Some(pos) => name.slice_to(pos) + Some(pos) => name[..pos] } }) } @@ -404,7 +404,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { match name.rposition_elem(&dot) { None | Some(0) => None, Some(1) if name == b".." => None, - Some(pos) => Some(name.slice_from(pos+1)) + Some(pos) => Some(name[pos+1..]) } } } @@ -480,7 +480,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { let extlen = extension.container_as_bytes().len(); match (name.rposition_elem(&dot), extlen) { (None, 0) | (Some(0), 0) => None, - (Some(idx), 0) => Some(name.slice_to(idx).to_vec()), + (Some(idx), 0) => Some(name[..idx].to_vec()), (idx, extlen) => { let idx = match idx { None | Some(0) => name.len(), @@ -489,7 +489,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { let mut v; v = Vec::with_capacity(idx + extlen + 1); - v.push_all(name.slice_to(idx)); + v.push_all(name[..idx]); v.push(dot); v.push_all(extension.container_as_bytes()); Some(v) diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 805db000686..2425b40fef4 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -165,7 +165,7 @@ impl GenericPathUnsafe for Path { None => { self.repr = Path::normalize(filename); } - Some(idx) if self.repr.slice_from(idx+1) == b".." => { + Some(idx) if self.repr[idx+1..] == b".." => { let mut v = Vec::with_capacity(self.repr.len() + 1 + filename.len()); v.push_all(self.repr.as_slice()); v.push(SEP_BYTE); @@ -175,7 +175,7 @@ impl GenericPathUnsafe for Path { } Some(idx) => { let mut v = Vec::with_capacity(idx + 1 + filename.len()); - v.push_all(self.repr.slice_to(idx+1)); + v.push_all(self.repr[..idx+1]); v.push_all(filename); // FIXME: this is slow self.repr = Path::normalize(v.as_slice()); @@ -216,9 +216,9 @@ impl GenericPath for Path { match self.sepidx { None if b".." == self.repr.as_slice() => self.repr.as_slice(), None => dot_static, - Some(0) => self.repr.slice_to(1), - Some(idx) if self.repr.slice_from(idx+1) == b".." => self.repr.as_slice(), - Some(idx) => self.repr.slice_to(idx) + Some(0) => self.repr[..1], + Some(idx) if self.repr[idx+1..] == b".." => self.repr.as_slice(), + Some(idx) => self.repr[..idx] } } @@ -227,9 +227,9 @@ impl GenericPath for Path { None if b"." == self.repr.as_slice() || b".." == self.repr.as_slice() => None, None => Some(self.repr.as_slice()), - Some(idx) if self.repr.slice_from(idx+1) == b".." => None, - Some(0) if self.repr.slice_from(1).is_empty() => None, - Some(idx) => Some(self.repr.slice_from(idx+1)) + Some(idx) if self.repr[idx+1..] == b".." => None, + Some(0) if self.repr[1..].is_empty() => None, + Some(idx) => Some(self.repr[idx+1..]) } } @@ -371,7 +371,7 @@ impl Path { // borrowck is being very picky let val = { let is_abs = !v.as_slice().is_empty() && v.as_slice()[0] == SEP_BYTE; - let v_ = if is_abs { v.as_slice().slice_from(1) } else { v.as_slice() }; + let v_ = if is_abs { v.as_slice()[1..] } else { v.as_slice() }; let comps = normalize_helper(v_, is_abs); match comps { None => None, @@ -410,7 +410,7 @@ impl Path { /// A path of "/" yields no components. A path of "." yields one component. pub fn components<'a>(&'a self) -> Components<'a> { let v = if self.repr[0] == SEP_BYTE { - self.repr.slice_from(1) + self.repr[1..] } else { self.repr.as_slice() }; let mut ret = v.split(is_sep_byte); if v.is_empty() { -- cgit 1.4.1-3-g733a5 From cd21e4a72c0175d226acc837d1886cfdfa40fe68 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Sun, 5 Oct 2014 12:22:42 +1300 Subject: Rename slice::Slice --- src/libcollections/hash/sip.rs | 2 +- src/libcollections/slice.rs | 4 ++-- src/libcollections/str.rs | 4 ++-- src/libcollections/vec.rs | 6 +++--- src/libcore/fmt/mod.rs | 2 +- src/libcore/option.rs | 16 ---------------- src/libcore/prelude.rs | 3 +-- src/libcore/result.rs | 21 --------------------- src/libcore/slice.rs | 8 ++++---- src/libgraphviz/maybe_owned_vec.rs | 4 ++-- src/libstd/ascii.rs | 2 +- src/libstd/c_vec.rs | 4 ++-- src/libstd/dynamic_lib.rs | 2 +- src/libstd/io/extensions.rs | 2 +- src/libstd/io/mem.rs | 2 +- src/libstd/io/mod.rs | 2 +- src/libstd/os.rs | 2 +- src/libstd/path/mod.rs | 2 +- src/libstd/path/posix.rs | 4 ++-- src/libstd/path/windows.rs | 2 +- src/libstd/prelude.rs | 2 +- src/libsyntax/test.rs | 2 +- 22 files changed, 30 insertions(+), 68 deletions(-) (limited to 'src/libstd/path') diff --git a/src/libcollections/hash/sip.rs b/src/libcollections/hash/sip.rs index f3798e5f9e0..ab182bd5602 100644 --- a/src/libcollections/hash/sip.rs +++ b/src/libcollections/hash/sip.rs @@ -273,7 +273,7 @@ mod tests { use str::Str; use string::String; - use slice::{Slice, ImmutableSlice}; + use slice::{AsSlice, ImmutableSlice}; use vec::Vec; use super::super::{Hash, Writer}; diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 253375aabe8..e07f6dbd35d 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -98,7 +98,7 @@ use core::iter::{range_step, MultiplicativeIterator}; use MutableSeq; use vec::Vec; -pub use core::slice::{Chunks, Slice, ImmutableSlice, ImmutablePartialEqSlice}; +pub use core::slice::{Chunks, AsSlice, ImmutableSlice, ImmutablePartialEqSlice}; pub use core::slice::{ImmutableOrdSlice, MutableSlice, Items, MutItems}; pub use core::slice::{MutSplits, MutChunks, Splits}; pub use core::slice::{bytes, mut_ref_slice, ref_slice, MutableCloneableSlice}; @@ -117,7 +117,7 @@ pub trait VectorVector { fn connect_vec(&self, sep: &T) -> Vec; } -impl<'a, T: Clone, V: Slice> VectorVector for &'a [V] { +impl<'a, T: Clone, V: AsSlice> 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); diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 3976367a76a..aabf5544954 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -61,7 +61,7 @@ use core::iter::AdditiveIterator; use core::mem; use core::prelude::{Char, Clone, Collection, Eq, Equiv, ImmutableSlice}; use core::prelude::{Iterator, MutableSlice, None, Option, Ord, Ordering}; -use core::prelude::{PartialEq, PartialOrd, Result, Slice, Some, Tuple2}; +use core::prelude::{PartialEq, PartialOrd, Result, AsSlice, Some, Tuple2}; use core::prelude::{range}; use {Deque, MutableSeq}; @@ -880,7 +880,7 @@ mod tests { use {Collection, MutableSeq}; use super::*; - use std::slice::{Slice, ImmutableSlice}; + use std::slice::{AsSlice, ImmutableSlice}; use string::String; use vec::Vec; diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 7b4cf4900f2..b995af952f1 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -547,7 +547,7 @@ impl PartialOrd for Vec { impl Eq for Vec {} #[experimental] -impl> Equiv for Vec { +impl> Equiv for Vec { #[inline] fn equiv(&self, other: &V) -> bool { self.as_slice() == other.as_slice() } } @@ -1605,7 +1605,7 @@ impl Vec { } } -impl Slice for Vec { +impl AsSlice for Vec { /// Returns a slice into `self`. /// /// # Example @@ -1623,7 +1623,7 @@ impl Slice for Vec { } } -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()); diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 28ee522346f..093f5896aad 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; use result::{Ok, Err}; use result; -use slice::{Slice, ImmutableSlice}; +use slice::{AsSlice, ImmutableSlice}; use slice; use str::StrSlice; use str; diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 1e353708730..ec7d655b087 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -149,7 +149,6 @@ use iter::{Iterator, DoubleEndedIterator, FromIterator, ExactSize}; use mem; use result::{Result, Ok, Err}; use slice; -use slice::Slice; // Note that this is not a lang item per se, but it has a hidden dependency on // `Iterator`, which is one. The compiler assumes that the `next` method of @@ -846,21 +845,6 @@ impl Option { // Trait implementations ///////////////////////////////////////////////////////////////////////////// -impl Slice for Option { - /// Convert from `Option` to `&[T]` (without copying) - #[inline] - #[stable] - fn as_slice<'a>(&'a self) -> &'a [T] { - match *self { - Some(ref x) => slice::ref_slice(x), - None => { - let result: &[_] = &[]; - result - } - } - } -} - impl Default for Option { #[inline] fn default() -> Option { None } diff --git a/src/libcore/prelude.rs b/src/libcore/prelude.rs index ead48092c4d..da17b113bf4 100644 --- a/src/libcore/prelude.rs +++ b/src/libcore/prelude.rs @@ -62,5 +62,4 @@ pub use tuple::{Tuple1, Tuple2, Tuple3, Tuple4}; pub use tuple::{Tuple5, Tuple6, Tuple7, Tuple8}; pub use tuple::{Tuple9, Tuple10, Tuple11, Tuple12}; pub use slice::{ImmutablePartialEqSlice, ImmutableOrdSlice}; -pub use slice::{MutableSlice}; -pub use slice::{Slice, ImmutableSlice}; +pub use slice::{AsSlice, ImmutableSlice, MutableSlice}; diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 9f347aacedc..f734ee8d0cb 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -280,7 +280,6 @@ use clone::Clone; use cmp::PartialEq; use std::fmt::Show; use slice; -use slice::Slice; use iter::{Iterator, DoubleEndedIterator, FromIterator, ExactSize}; use option::{None, Option, Some}; @@ -840,26 +839,6 @@ impl Result { } } -///////////////////////////////////////////////////////////////////////////// -// Trait implementations -///////////////////////////////////////////////////////////////////////////// - -impl Slice for Result { - /// Convert from `Result` to `&[T]` (without copying) - #[inline] - #[stable] - fn as_slice<'a>(&'a self) -> &'a [T] { - match *self { - Ok(ref x) => slice::ref_slice(x), - Err(_) => { - // work around lack of implicit coercion from fixed-size array to slice - let emp: &[_] = &[]; - emp - } - } - } -} - ///////////////////////////////////////////////////////////////////////////// // The Result Iterator ///////////////////////////////////////////////////////////////////////////// diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index e1afd1a647a..67503751742 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -1143,13 +1143,13 @@ impl<'a, T:Clone> MutableCloneableSlice for &'a mut [T] { /// Data that is viewable as a slice. #[unstable = "may merge with other traits"] -pub trait Slice { +pub trait AsSlice { /// Work with `self` as a slice. fn as_slice<'a>(&'a self) -> &'a [T]; } #[unstable = "trait is unstable"] -impl<'a,T> Slice for &'a [T] { +impl<'a,T> AsSlice for &'a [T] { #[inline(always)] fn as_slice<'a>(&'a self) -> &'a [T] { *self } } @@ -1828,7 +1828,7 @@ impl<'a,T:PartialEq> PartialEq for &'a [T] { impl<'a,T:Eq> Eq for &'a [T] {} #[unstable = "waiting for DST"] -impl<'a,T:PartialEq, V: Slice> Equiv for &'a [T] { +impl<'a,T:PartialEq, V: AsSlice> Equiv for &'a [T] { #[inline] fn equiv(&self, other: &V) -> bool { self.as_slice() == other.as_slice() } } @@ -1849,7 +1849,7 @@ impl<'a,T:PartialEq> PartialEq for &'a mut [T] { impl<'a,T:Eq> Eq for &'a mut [T] {} #[unstable = "waiting for DST"] -impl<'a,T:PartialEq, V: Slice> Equiv for &'a mut [T] { +impl<'a,T:PartialEq, V: AsSlice> Equiv for &'a mut [T] { #[inline] fn equiv(&self, other: &V) -> bool { self.as_slice() == other.as_slice() } } diff --git a/src/libgraphviz/maybe_owned_vec.rs b/src/libgraphviz/maybe_owned_vec.rs index 94e89dc6043..50d957e1381 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: Slice> Equiv for MaybeOwnedVector<'a, T> { +impl<'a, T: PartialEq, V: AsSlice> 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: Slice> 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 for MaybeOwnedVector<'b,T> { +impl<'b,T> AsSlice for MaybeOwnedVector<'b,T> { fn as_slice<'a>(&'a self) -> &'a [T] { match self { &Growable(ref v) => v.as_slice(), diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index fe2b8a15c73..7a36680b3a6 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::{ImmutableSlice, MutableSlice, Slice}; +use slice::{ImmutableSlice, MutableSlice, AsSlice}; use str::{Str, StrSlice}; use string::{mod, String}; use to_string::IntoStr; diff --git a/src/libstd/c_vec.rs b/src/libstd/c_vec.rs index d8a7305810f..95f8ab72016 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::Slice; +use slice::AsSlice; /// The type representing a foreign chunk of memory pub struct CVec { @@ -145,7 +145,7 @@ impl CVec { } } -impl Slice for CVec { +impl AsSlice for CVec { /// View the stored data as a slice. fn as_slice<'a>(&'a self) -> &'a [T] { unsafe { diff --git a/src/libstd/dynamic_lib.rs b/src/libstd/dynamic_lib.rs index bd2bd1ad090..5cd0b3010c5 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::{Slice,ImmutableSlice}; +use slice::{AsSlice,ImmutableSlice}; use str; use string::String; use vec::Vec; diff --git a/src/libstd/io/extensions.rs b/src/libstd/io/extensions.rs index a93f9826fa5..57741db5ae2 100644 --- a/src/libstd/io/extensions.rs +++ b/src/libstd/io/extensions.rs @@ -23,7 +23,7 @@ use num::Int; use option::{Option, Some, None}; use ptr::RawPtr; use result::{Ok, Err}; -use slice::{ImmutableSlice, Slice}; +use slice::{ImmutableSlice, AsSlice}; /// An iterator that reads a single byte on each iteration, /// until `.read_byte()` returns `EndOfFile`. diff --git a/src/libstd/io/mem.rs b/src/libstd/io/mem.rs index ca9692ee158..0f8e0ed52f8 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::Slice; +use slice::AsSlice; use vec::Vec; static BUF_CAPACITY: uint = 128; diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index d279b88a1c5..280aff71e23 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::{Slice, ImmutableSlice}; +use slice::{AsSlice, ImmutableSlice}; use str::{Str, StrSlice}; use str; use string::String; diff --git a/src/libstd/os.rs b/src/libstd/os.rs index c6948cccafe..bb642f1e48f 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::{Slice, ImmutableSlice, MutableSlice, ImmutablePartialEqSlice}; +use slice::{AsSlice, ImmutableSlice, MutableSlice, ImmutablePartialEqSlice}; use slice::CloneableVector; use str::{Str, StrSlice, StrAllocating}; use string::String; diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index 63c81695aff..6a122990246 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -76,7 +76,7 @@ use option::{Option, None, Some}; use str; use str::{MaybeOwned, Str, StrSlice}; use string::String; -use slice::{Slice, CloneableVector}; +use slice::{AsSlice, CloneableVector}; use slice::{ImmutablePartialEqSlice, ImmutableSlice}; use vec::Vec; diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 2425b40fef4..196ac7507ea 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -21,7 +21,7 @@ use iter::{DoubleEndedIterator, AdditiveIterator, Extendable, Iterator, Map}; use option::{Option, None, Some}; use str::Str; use str; -use slice::{CloneableVector, Splits, Slice, VectorVector, +use slice::{CloneableVector, Splits, AsSlice, VectorVector, ImmutablePartialEqSlice, ImmutableSlice}; use vec::Vec; @@ -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 803db4848ad..ec3f87bc45a 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::{Slice, ImmutableSlice}; +use slice::{AsSlice, 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 48ddfeaf5ff..a1e74c7254e 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -87,7 +87,7 @@ #[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::{AsSlice, 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/libsyntax/test.rs b/src/libsyntax/test.rs index d2c0ebd4393..3f5b524a9b5 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -414,7 +414,7 @@ fn mk_test_module(cx: &mut TestCtxt) -> (P, Option) { let mainfn = (quote_item!(&mut cx.ext_cx, pub fn main() { #![main] - use std::slice::Slice; + use std::slice::AsSlice; test::test_main_static(::std::os::args().as_slice(), TESTS); } )).unwrap(); -- cgit 1.4.1-3-g733a5