diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2013-06-13 02:56:09 +1000 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2013-06-13 10:19:34 +1000 |
| commit | 641910dc1340b7786fd758282bac88639a58ddcd (patch) | |
| tree | a183dcf81a44a02ccc36116e463617b8350c012c /src/libstd | |
| parent | 84bed9769b5d15871481b657860ad6a7d0a62f42 (diff) | |
| download | rust-641910dc1340b7786fd758282bac88639a58ddcd.tar.gz rust-641910dc1340b7786fd758282bac88639a58ddcd.zip | |
std: make all strings Equiv-alent to each other, generalise Path.push_many to take any type of string.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/path.rs | 12 | ||||
| -rw-r--r-- | src/libstd/prelude.rs | 2 | ||||
| -rw-r--r-- | src/libstd/str.rs | 16 |
3 files changed, 21 insertions, 9 deletions
diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 02772604e45..9c4e8f08358 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -22,7 +22,7 @@ use iterator::IteratorUtil; 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 @@ impl GenericPath for PosixPath { 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 @@ impl GenericPath for WindowsPath { } } - 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()) } diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index e969c5d4e3a..4400cb5de98 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -64,7 +64,7 @@ pub use path::PosixPath; 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}; diff --git a/src/libstd/str.rs b/src/libstd/str.rs index fdf12d406e8..c928933f4a7 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -729,10 +729,22 @@ impl Ord for @str { } #[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 |
