]> git.lizzy.rs Git - rust.git/commitdiff
std: make all strings Equiv-alent to each other, generalise Path.push_many to take...
authorHuon Wilson <dbau.pp+github@gmail.com>
Wed, 12 Jun 2013 16:56:09 +0000 (02:56 +1000)
committerHuon Wilson <dbau.pp+github@gmail.com>
Thu, 13 Jun 2013 00:19:34 +0000 (10:19 +1000)
src/libstd/path.rs
src/libstd/prelude.rs
src/libstd/str.rs

index 02772604e45ca4ac3fa214ca8905c4b56a578db6..9c4e8f083584c542adcaa501d18dbb3f1bfc7f6e 100644 (file)
@@ -22,7 +22,7 @@
 use libc;
 use option::{None, Option, Some};
 use str;
-use str::{StrSlice, StrVector};
+use str::{Str, StrSlice, StrVector};
 use to_str::ToStr;
 use ascii::{AsciiCast, AsciiStr};
 use old_iter::BaseIter;
@@ -102,7 +102,7 @@ pub trait GenericPath {
     fn push_rel(&self, (&Self)) -> Self;
     /// Returns a new Path consisting of the path given by the given vector
     /// of strings, relative to `self`.
-    fn push_many(&self, (&[~str])) -> Self;
+    fn push_many<S: Str>(&self, (&[S])) -> Self;
     /// Identical to `dir_path` except in the case where `self` has only one
     /// component. In this case, `pop` returns the empty path.
     fn pop(&self) -> Self;
@@ -566,10 +566,10 @@ fn is_restricted(&self) -> bool {
         false
     }
 
-    fn push_many(&self, cs: &[~str]) -> PosixPath {
+    fn push_many<S: Str>(&self, cs: &[S]) -> PosixPath {
         let mut v = copy self.components;
         for cs.each |e| {
-            for e.split_iter(windows::is_sep).advance |s| {
+            for e.as_slice().split_iter(windows::is_sep).advance |s| {
                 if !s.is_empty() {
                     v.push(s.to_owned())
                 }
@@ -823,10 +823,10 @@ fn is_restricted(&self) -> bool {
         }
     }
 
-    fn push_many(&self, cs: &[~str]) -> WindowsPath {
+    fn push_many<S: Str>(&self, cs: &[S]) -> WindowsPath {
         let mut v = copy self.components;
         for cs.each |e| {
-            for e.split_iter(windows::is_sep).advance |s| {
+            for e.as_slice().split_iter(windows::is_sep).advance |s| {
                 if !s.is_empty() {
                     v.push(s.to_owned())
                 }
index e969c5d4e3a15d3464bc92300add41895e1ed02d..4400cb5de9833522788f52237b37fd03f548b1e1 100644 (file)
@@ -64,7 +64,7 @@
 pub use path::WindowsPath;
 pub use ptr::RawPtr;
 pub use ascii::{Ascii, AsciiCast, OwnedAsciiCast, AsciiStr};
-pub use str::{StrVector, StrSlice, OwnedStr, StrUtil, NullTerminatedStr};
+pub use str::{Str, StrVector, StrSlice, OwnedStr, StrUtil, NullTerminatedStr};
 pub use from_str::{FromStr};
 pub use to_bytes::IterBytes;
 pub use to_str::{ToStr, ToStrConsume};
index fdf12d406e81f83a5ebb6589f8c4abedb90b9ff6..c928933f4a74ca10bedee563f259a17bd53bb2f9 100644 (file)
@@ -729,10 +729,22 @@ fn gt(&self, other: &@str) -> bool { gt((*self), (*other)) }
 }
 
 #[cfg(not(test))]
-impl<'self> Equiv<~str> for &'self str {
+impl<'self, S: Str> Equiv<S> for &'self str {
     #[inline(always)]
-    fn equiv(&self, other: &~str) -> bool { eq_slice(*self, *other) }
+    fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) }
 }
+#[cfg(not(test))]
+impl<'self, S: Str> Equiv<S> for @str {
+    #[inline(always)]
+    fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) }
+}
+
+#[cfg(not(test))]
+impl<'self, S: Str> Equiv<S> for ~str {
+    #[inline(always)]
+    fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) }
+}
+
 
 /*
 Section: Iterating through strings