Skip to content

Commit 641910d

Browse files
committed
std: make all strings Equiv-alent to each other, generalise Path.push_many to take any type of string.
1 parent 84bed97 commit 641910d

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

src/libstd/path.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use iterator::IteratorUtil;
2222
use libc;
2323
use option::{None, Option, Some};
2424
use str;
25-
use str::{StrSlice, StrVector};
25+
use str::{Str, StrSlice, StrVector};
2626
use to_str::ToStr;
2727
use ascii::{AsciiCast, AsciiStr};
2828
use old_iter::BaseIter;
@@ -102,7 +102,7 @@ pub trait GenericPath {
102102
fn push_rel(&self, (&Self)) -> Self;
103103
/// Returns a new Path consisting of the path given by the given vector
104104
/// of strings, relative to `self`.
105-
fn push_many(&self, (&[~str])) -> Self;
105+
fn push_many<S: Str>(&self, (&[S])) -> Self;
106106
/// Identical to `dir_path` except in the case where `self` has only one
107107
/// component. In this case, `pop` returns the empty path.
108108
fn pop(&self) -> Self;
@@ -566,10 +566,10 @@ impl GenericPath for PosixPath {
566566
false
567567
}
568568

569-
fn push_many(&self, cs: &[~str]) -> PosixPath {
569+
fn push_many<S: Str>(&self, cs: &[S]) -> PosixPath {
570570
let mut v = copy self.components;
571571
for cs.each |e| {
572-
for e.split_iter(windows::is_sep).advance |s| {
572+
for e.as_slice().split_iter(windows::is_sep).advance |s| {
573573
if !s.is_empty() {
574574
v.push(s.to_owned())
575575
}
@@ -823,10 +823,10 @@ impl GenericPath for WindowsPath {
823823
}
824824
}
825825

826-
fn push_many(&self, cs: &[~str]) -> WindowsPath {
826+
fn push_many<S: Str>(&self, cs: &[S]) -> WindowsPath {
827827
let mut v = copy self.components;
828828
for cs.each |e| {
829-
for e.split_iter(windows::is_sep).advance |s| {
829+
for e.as_slice().split_iter(windows::is_sep).advance |s| {
830830
if !s.is_empty() {
831831
v.push(s.to_owned())
832832
}

src/libstd/prelude.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub use path::PosixPath;
6464
pub use path::WindowsPath;
6565
pub use ptr::RawPtr;
6666
pub use ascii::{Ascii, AsciiCast, OwnedAsciiCast, AsciiStr};
67-
pub use str::{StrVector, StrSlice, OwnedStr, StrUtil, NullTerminatedStr};
67+
pub use str::{Str, StrVector, StrSlice, OwnedStr, StrUtil, NullTerminatedStr};
6868
pub use from_str::{FromStr};
6969
pub use to_bytes::IterBytes;
7070
pub use to_str::{ToStr, ToStrConsume};

src/libstd/str.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,10 +729,22 @@ impl Ord for @str {
729729
}
730730

731731
#[cfg(not(test))]
732-
impl<'self> Equiv<~str> for &'self str {
732+
impl<'self, S: Str> Equiv<S> for &'self str {
733733
#[inline(always)]
734-
fn equiv(&self, other: &~str) -> bool { eq_slice(*self, *other) }
734+
fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) }
735735
}
736+
#[cfg(not(test))]
737+
impl<'self, S: Str> Equiv<S> for @str {
738+
#[inline(always)]
739+
fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) }
740+
}
741+
742+
#[cfg(not(test))]
743+
impl<'self, S: Str> Equiv<S> for ~str {
744+
#[inline(always)]
745+
fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) }
746+
}
747+
736748

737749
/*
738750
Section: Iterating through strings

0 commit comments

Comments
 (0)