summary refs log tree commit diff
path: root/src/libstd/path.rs
diff options
context:
space:
mode:
authorAaron Turon <aturon@mozilla.com>2015-02-11 23:16:32 -0800
committerAaron Turon <aturon@mozilla.com>2015-02-18 15:23:58 -0800
commita99e698628cbd396c8100ef776d10ac61d911847 (patch)
tree889679e9690bbb6303f75abfb9bdd0ec4beedfcc /src/libstd/path.rs
parent9bb3b3772d4be69b0f619bd9456255a9e3bc7d9e (diff)
downloadrust-a99e698628cbd396c8100ef776d10ac61d911847.tar.gz
rust-a99e698628cbd396c8100ef776d10ac61d911847.zip
Stabilize std::borrow
This commit stabilizes `std::borrow`, making the following modifications
to catch up the API with language changes:

* It renames `BorrowFrom` to `Borrow`, as was originally intended (but
  blocked for technical reasons), and reorders the parameters
  accordingly.

* It moves the type parameter of `ToOwned` to an associated type. This
  is somewhat less flexible, in that each borrowed type must have a
  unique owned type, but leads to a significant simplification for
  `Cow`. Flexibility can be regained by using newtyped slices, which is
  advisable for other reasons anyway.

* It removes the owned type parameter from `Cow`, making the type much
  less verbose.

* Deprecates the `is_owned` and `is_borrowed` predicates in favor of
  direct matching.

The above API changes are relatively minor; the basic functionality
remains the same, and essentially the whole module is now marked
`#[stable]`.

[breaking-change]
Diffstat (limited to 'src/libstd/path.rs')
-rwxr-xr-xsrc/libstd/path.rs18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/libstd/path.rs b/src/libstd/path.rs
index 1d992668900..1f7129bf361 100755
--- a/src/libstd/path.rs
+++ b/src/libstd/path.rs
@@ -108,12 +108,11 @@
 use core::prelude::*;
 
 use ascii::*;
-use borrow::BorrowFrom;
+use borrow::{Borrow, ToOwned, Cow};
 use cmp;
 use iter;
 use mem;
 use ops::{self, Deref};
-use string::CowString;
 use vec::Vec;
 use fmt;
 
@@ -982,12 +981,17 @@ impl ops::Deref for PathBuf {
     }
 }
 
-impl BorrowFrom<PathBuf> for Path {
-    fn borrow_from(owned: &PathBuf) -> &Path {
-        owned.deref()
+impl Borrow<Path> for PathBuf {
+    fn borrow(&self) -> &Path {
+        self.deref()
     }
 }
 
+impl ToOwned for Path {
+    type Owned = PathBuf;
+    fn to_owned(&self) -> PathBuf { self.to_path_buf() }
+}
+
 impl cmp::PartialEq for PathBuf {
     fn eq(&self, other: &PathBuf) -> bool {
         self.components() == other.components()
@@ -1066,10 +1070,10 @@ impl Path {
         self.inner.to_str()
     }
 
-    /// Convert a `Path` to a `CowString`.
+    /// Convert a `Path` to a `Cow<str>`.
     ///
     /// Any non-Unicode sequences are replaced with U+FFFD REPLACEMENT CHARACTER.
-    pub fn to_string_lossy(&self) -> CowString {
+    pub fn to_string_lossy(&self) -> Cow<str> {
         self.inner.to_string_lossy()
     }