From 9fc51efe3344a32d9e522f08383f052277b6ab63 Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Mon, 30 Mar 2015 15:15:27 -0700 Subject: Stabilize `std::convert` and related code * 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] --- src/libstd/sys/unix/ext.rs | 9 +-------- src/libstd/sys/unix/fs2.rs | 4 ++-- src/libstd/sys/unix/process2.rs | 2 +- 3 files changed, 4 insertions(+), 11 deletions(-) (limited to 'src/libstd/sys') diff --git a/src/libstd/sys/unix/ext.rs b/src/libstd/sys/unix/ext.rs index 0805949d560..d197d04c0a4 100644 --- a/src/libstd/sys/unix/ext.rs +++ b/src/libstd/sys/unix/ext.rs @@ -138,7 +138,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; @@ -175,10 +175,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; } #[stable(feature = "rust1", since = "1.0.0")] @@ -189,9 +185,6 @@ pub mod ffi { fn as_bytes(&self) -> &[u8] { &self.as_inner().inner } - fn to_cstring(&self) -> Result { - CString::new(self.as_bytes()) - } } } diff --git a/src/libstd/sys/unix/fs2.rs b/src/libstd/sys/unix/fs2.rs index 202e5ddaec4..c7bfb8604bc 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 { - 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)) } pub fn mkdir(p: &Path) -> io::Result<()> { 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>(&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() { -- cgit 1.4.1-3-g733a5