diff options
| author | Aaron Turon <aturon@mozilla.com> | 2015-03-30 15:15:27 -0700 |
|---|---|---|
| committer | Aaron Turon <aturon@mozilla.com> | 2015-03-31 11:24:38 -0700 |
| commit | 9fc51efe3344a32d9e522f08383f052277b6ab63 (patch) | |
| tree | 29eb89ae9f4b70cc88642eb6b66cbb9398c41ae4 /src/libstd/sys | |
| parent | 6cf3b0b74aadcc1fe87adbd2c74876a1f6c920b3 (diff) | |
| download | rust-9fc51efe3344a32d9e522f08383f052277b6ab63.tar.gz rust-9fc51efe3344a32d9e522f08383f052277b6ab63.zip | |
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]
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/unix/ext.rs | 9 | ||||
| -rw-r--r-- | src/libstd/sys/unix/fs2.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sys/unix/process2.rs | 2 |
3 files changed, 4 insertions, 11 deletions
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<CString, NulError>; } #[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, NulError> { - 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<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)) } 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<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() { |
