diff options
| author | bors <bors@rust-lang.org> | 2014-11-26 12:02:16 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-11-26 12:02:16 +0000 |
| commit | 8fb027e398ef756b7b02a270ef0304be92e70f4d (patch) | |
| tree | e842ec33ca78ddc8223bdbfc0e6839f7d3643618 /src/libstd/path | |
| parent | 61af40278909eb899f1bdfbb8c45d4e4fb3dad5d (diff) | |
| parent | 3293ab14e24d136d0482bb18afef577aebed251e (diff) | |
| download | rust-8fb027e398ef756b7b02a270ef0304be92e70f4d.tar.gz rust-8fb027e398ef756b7b02a270ef0304be92e70f4d.zip | |
auto merge of #19252 : japaric/rust/cow, r=aturon
- Add `IntoCow` trait, and put it in the prelude
- Add `is_owned`/`is_borrowed` methods to `Cow`
- Add `CowString`/`CowVec` type aliases (to `Cow<'_, String, str>`/`Cow<'_, Vec, [T]>` respectively)
- `Cow` implements: `Show`, `Hash`, `[Partial]{Eq,Ord}`
- `impl BorrowFrom<Cow<'a, T, B>> for B`
[breaking-change]s:
- `IntoMaybeOwned` has been removed from the prelude
- libcollections: `SendStr` is now an alias to `CowString<'static>` (it was aliased to `MaybeOwned<'static>`)
- libgraphviz:
- `LabelText` variants now wrap `CowString` instead of `MaybeOwned`
- `Nodes` and `Edges` are now type aliases to `CowVec` (they were aliased to `MaybeOwnedVec`)
- libstd/path: `Display::as_maybe_owned` has been renamed to `Display::as_cow` and now returns a `CowString`
- These functions now accept/return `Cow` instead of `MaybeOwned[Vector]`:
- libregex: `Replacer::reg_replace`
- libcollections: `str::from_utf8_lossy`
- libgraphviz: `Id::new`, `Id::name`, `LabelText::pre_escaped_content`
- libstd: `TaskBuilder::named`
r? @aturon
Diffstat (limited to 'src/libstd/path')
| -rw-r--r-- | src/libstd/path/mod.rs | 6 | ||||
| -rw-r--r-- | src/libstd/path/posix.rs | 4 | ||||
| -rw-r--r-- | src/libstd/path/windows.rs | 4 |
3 files changed, 7 insertions, 7 deletions
diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index a185a29a700..ce3440ead40 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -74,7 +74,7 @@ use fmt; use iter::Iterator; use option::{Option, None, Some}; use str; -use str::{MaybeOwned, Str, StrPrelude}; +use str::{CowString, MaybeOwned, Str, StrPrelude}; use string::String; use slice::{AsSlice, CloneSliceAllocPrelude}; use slice::{PartialEqSlicePrelude, SlicePrelude}; @@ -830,7 +830,7 @@ pub struct Display<'a, P:'a> { impl<'a, P: GenericPath> fmt::Show for Display<'a, P> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - self.as_maybe_owned().as_slice().fmt(f) + self.as_cow().fmt(f) } } @@ -840,7 +840,7 @@ impl<'a, P: GenericPath> Display<'a, P> { /// If the path is not UTF-8, invalid sequences will be replaced with the /// Unicode replacement char. This involves allocation. #[inline] - pub fn as_maybe_owned(&self) -> MaybeOwned<'a> { + pub fn as_cow(&self) -> CowString<'a> { String::from_utf8_lossy(if self.filename { match self.path.filename() { None => { diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 2b444fdc32b..bdce759a1df 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -551,14 +551,14 @@ mod tests { ($path:expr, $exp:expr) => ( { let path = Path::new($path); - let mo = path.display().as_maybe_owned(); + let mo = path.display().as_cow(); assert!(mo.as_slice() == $exp); } ); ($path:expr, $exp:expr, filename) => ( { let path = Path::new($path); - let mo = path.filename_display().as_maybe_owned(); + let mo = path.filename_display().as_cow(); assert!(mo.as_slice() == $exp); } ) diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 9f81de72980..fc367710131 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -1326,10 +1326,10 @@ mod tests { assert_eq!(path.filename_display().to_string(), "".to_string()); let path = Path::new("foo"); - let mo = path.display().as_maybe_owned(); + let mo = path.display().as_cow(); assert_eq!(mo.as_slice(), "foo"); let path = Path::new(b"\\"); - let mo = path.filename_display().as_maybe_owned(); + let mo = path.filename_display().as_cow(); assert_eq!(mo.as_slice(), ""); } |
