about summary refs log tree commit diff
path: root/src/libstd/sys
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/sys
parent94137a37e90f2fc5faf725965b419944e14ad271 (diff)
parent9fc51efe3344a32d9e522f08383f052277b6ab63 (diff)
downloadrust-da04788efca6ec1e421139fb4916a5aacd49a2e2.tar.gz
rust-da04788efca6ec1e421139fb4916a5aacd49a2e2.zip
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/sys')
-rw-r--r--src/libstd/sys/unix/ext.rs9
-rw-r--r--src/libstd/sys/unix/fs2.rs4
-rw-r--r--src/libstd/sys/unix/process2.rs2
3 files changed, 4 insertions, 11 deletions
diff --git a/src/libstd/sys/unix/ext.rs b/src/libstd/sys/unix/ext.rs
index 080cf5620fc..fbfbb40701f 100644
--- a/src/libstd/sys/unix/ext.rs
+++ b/src/libstd/sys/unix/ext.rs
@@ -207,7 +207,7 @@ pub mod io {
 /// Unix-specific extension to the primitives in the `std::ffi` module
 #[stable(feature = "rust1", since = "1.0.0")]
 pub mod ffi {
-    use ffi::{CString, NulError, OsStr, OsString};
+    use ffi::{OsStr, OsString};
     use mem;
     use prelude::v1::*;
     use sys::os_str::Buf;
@@ -244,10 +244,6 @@ pub mod ffi {
         /// Get the underlying byte view of the `OsStr` slice.
         #[stable(feature = "rust1", since = "1.0.0")]
         fn as_bytes(&self) -> &[u8];
-
-        /// Convert the `OsStr` slice into a `CString`.
-        #[stable(feature = "rust1", since = "1.0.0")]
-        fn to_cstring(&self) -> Result<CString, NulError>;
     }
 
     #[stable(feature = "rust1", since = "1.0.0")]
@@ -258,9 +254,6 @@ pub mod ffi {
         fn as_bytes(&self) -> &[u8] {
             &self.as_inner().inner
         }
-        fn to_cstring(&self) -> Result<CString, NulError> {
-            CString::new(self.as_bytes())
-        }
     }
 }
 
diff --git a/src/libstd/sys/unix/fs2.rs b/src/libstd/sys/unix/fs2.rs
index 80fc1235a31..c5d3dce2634 100644
--- a/src/libstd/sys/unix/fs2.rs
+++ b/src/libstd/sys/unix/fs2.rs
@@ -276,8 +276,8 @@ impl File {
 }
 
 fn cstr(path: &Path) -> io::Result<CString> {
-    let cstring = try!(path.as_os_str().to_cstring());
-    Ok(cstring)
+    path.as_os_str().to_cstring().ok_or(
+        io::Error::new(io::ErrorKind::InvalidInput, "path contained a null", None))
 }
 
 impl FromInner<c_int> for File {
diff --git a/src/libstd/sys/unix/process2.rs b/src/libstd/sys/unix/process2.rs
index 20c409154b8..c2a8b26aef4 100644
--- a/src/libstd/sys/unix/process2.rs
+++ b/src/libstd/sys/unix/process2.rs
@@ -54,7 +54,7 @@ impl Command {
         self.args.push(arg.to_cstring().unwrap())
     }
     pub fn args<'a, I: Iterator<Item = &'a OsStr>>(&mut self, args: I) {
-        self.args.extend(args.map(|s| OsStrExt::to_cstring(s).unwrap()))
+        self.args.extend(args.map(|s| s.to_cstring().unwrap()))
     }
     fn init_env_map(&mut self) {
         if self.env.is_none() {