about summary refs log tree commit diff
path: root/src/libstd/path.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-03-31 11:26:10 -0700
committerAlex Crichton <alex@alexcrichton.com>2015-03-31 15:53:26 -0700
commitda04788efca6ec1e421139fb4916a5aacd49a2e2 (patch)
tree91bb44f384c9927d40392696e9b356fd22b77bd5 /src/libstd/path.rs
parent94137a37e90f2fc5faf725965b419944e14ad271 (diff)
parent9fc51efe3344a32d9e522f08383f052277b6ab63 (diff)
rollup merge of #23875: aturon/revise-convert-2
* Marks `#[stable]` the contents of the `std::convert` module.

* Added methods `PathBuf::as_path`, `OsString::as_os_str`,
  `String::as_str`, `Vec::{as_slice, as_mut_slice}`.

* Deprecates `OsStr::from_str` in favor of a new, stable, and more
  general `OsStr::new`.

* Adds unstable methods `OsString::from_bytes` and `OsStr::{to_bytes,
  to_cstring}` for ergonomic FFI usage.

[breaking-change]

r? @alexcrichton
Diffstat (limited to 'src/libstd/path.rs')
-rw-r--r--src/libstd/path.rs15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/libstd/path.rs b/src/libstd/path.rs
index 58d3ae9f7cf..36a5d1465f0 100644
--- a/src/libstd/path.rs
+++ b/src/libstd/path.rs
@@ -35,7 +35,6 @@
 //! To build or modify paths, use `PathBuf`:
 //!
 //! ```rust
-//! # #![feature(convert)]
 //! use std::path::PathBuf;
 //!
 //! let mut path = PathBuf::from("c:\\");
@@ -521,9 +520,9 @@ impl<'a> Component<'a> {
     pub fn as_os_str(self) -> &'a OsStr {
         match self {
             Component::Prefix(p) => p.as_os_str(),
-            Component::RootDir => OsStr::from_str(MAIN_SEP_STR),
-            Component::CurDir => OsStr::from_str("."),
-            Component::ParentDir => OsStr::from_str(".."),
+            Component::RootDir => OsStr::new(MAIN_SEP_STR),
+            Component::CurDir => OsStr::new("."),
+            Component::ParentDir => OsStr::new(".."),
             Component::Normal(path) => path,
         }
     }
@@ -893,7 +892,6 @@ impl<'a> cmp::Ord for Components<'a> {
 /// # Examples
 ///
 /// ```
-/// # #![feature(convert)]
 /// use std::path::PathBuf;
 ///
 /// let mut path = PathBuf::from("c:\\");
@@ -918,6 +916,12 @@ impl PathBuf {
         PathBuf { inner: OsString::new() }
     }
 
+    /// Coerce to a `Path` slice.
+    #[stable(feature = "rust1", since = "1.0.0")]
+    pub fn as_path(&self) -> &Path {
+        self
+    }
+
     /// Extend `self` with `path`.
     ///
     /// If `path` is absolute, it replaces the current path.
@@ -985,7 +989,6 @@ impl PathBuf {
     /// # Examples
     ///
     /// ```
-    /// # #![feature(convert)]
     /// use std::path::PathBuf;
     ///
     /// let mut buf = PathBuf::from("/");