diff options
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/error.rs | 8 | ||||
| -rw-r--r-- | src/libstd/io/mod.rs | 13 | ||||
| -rw-r--r-- | src/libstd/lib.rs | 2 | ||||
| -rw-r--r-- | src/libstd/panic.rs | 4 | ||||
| -rw-r--r-- | src/libstd/process.rs | 83 | ||||
| -rw-r--r-- | src/libstd/sync/rwlock.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/unix/ext/mod.rs | 10 | ||||
| -rw-r--r-- | src/libstd/sys/unix/rand.rs | 4 |
8 files changed, 107 insertions, 19 deletions
diff --git a/src/libstd/error.rs b/src/libstd/error.rs index 166439692d4..231b0be9276 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -57,6 +57,7 @@ use borrow::Cow; use cell; use char; use convert; +use core::array; use fmt::{self, Debug, Display}; use mem::transmute; use num; @@ -282,6 +283,13 @@ impl Error for num::TryFromIntError { } } +#[unstable(feature = "try_from", issue = "33417")] +impl Error for array::TryFromSliceError { + fn description(&self) -> &str { + self.__description() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl Error for num::ParseFloatError { fn description(&self) -> &str { diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 074ab3ebd8f..dec281212a5 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -736,10 +736,10 @@ pub trait Read { /// Transforms this `Read` instance to an [`Iterator`] over its bytes. /// - /// The returned type implements [`Iterator`] where the `Item` is [`Result`]`<`[`u8`]`, - /// R::Err>`. The yielded item is [`Ok`] if a byte was successfully read and - /// [`Err`] otherwise for I/O errors. EOF is mapped to returning [`None`] from - /// this iterator. + /// The returned type implements [`Iterator`] where the `Item` is + /// [`Result`]`<`[`u8`]`, `[`io::Error`]>`. + /// The yielded item is [`Ok`] if a byte was successfully read and [`Err`] + /// otherwise. EOF is mapped to returning [`None`] from this iterator. /// /// # Examples /// @@ -748,6 +748,7 @@ pub trait Read { /// [file]: ../fs/struct.File.html /// [`Iterator`]: ../../std/iter/trait.Iterator.html /// [`Result`]: ../../std/result/enum.Result.html + /// [`io::Error``]: ../../std/io/struct.Error.html /// [`u8`]: ../../std/primitive.u8.html /// [`Ok`]: ../../std/result/enum.Result.html#variant.Ok /// [`Err`]: ../../std/result/enum.Result.html#variant.Err @@ -1410,6 +1411,8 @@ pub trait BufRead: Read { /// /// If successful, this function will return the total number of bytes read. /// + /// An empty buffer returned indicates that the stream has reached EOF. + /// /// # Errors /// /// This function will ignore all instances of [`ErrorKind::Interrupted`] and @@ -1470,6 +1473,8 @@ pub trait BufRead: Read { /// /// If successful, this function will return the total number of bytes read. /// + /// An empty buffer returned indicates that the stream has reached EOF. + /// /// # Errors /// /// This function has the same error semantics as [`read_until`] and will diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 012883d0853..5cf1d225b90 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -243,6 +243,7 @@ #![feature(allow_internal_unsafe)] #![feature(allow_internal_unstable)] #![feature(align_offset)] +#![feature(array_error_internals)] #![feature(asm)] #![feature(attr_literals)] #![feature(box_syntax)] @@ -267,6 +268,7 @@ #![feature(core_intrinsics)] #![feature(dropck_eyepatch)] #![feature(exact_size_is_empty)] +#![feature(fixed_size_array)] #![feature(float_from_str_radix)] #![feature(fn_traits)] #![feature(fnbox)] diff --git a/src/libstd/panic.rs b/src/libstd/panic.rs index 97b09b7e2ad..385076e50dd 100644 --- a/src/libstd/panic.rs +++ b/src/libstd/panic.rs @@ -188,6 +188,8 @@ pub struct AssertUnwindSafe<T>( // * Types like Mutex/RwLock which are explicilty poisoned are unwind safe // * Our custom AssertUnwindSafe wrapper is indeed unwind safe #[stable(feature = "catch_unwind", since = "1.9.0")] +#[allow(unknown_lints)] +#[allow(auto_impl)] impl UnwindSafe for .. {} #[stable(feature = "catch_unwind", since = "1.9.0")] impl<'a, T: ?Sized> !UnwindSafe for &'a mut T {} @@ -221,6 +223,8 @@ impl<T: RefUnwindSafe + ?Sized> UnwindSafe for Arc<T> {} // only thing which doesn't implement it (which then transitively applies to // everything else). #[stable(feature = "catch_unwind", since = "1.9.0")] +#[allow(unknown_lints)] +#[allow(auto_impl)] impl RefUnwindSafe for .. {} #[stable(feature = "catch_unwind", since = "1.9.0")] impl<T: ?Sized> !RefUnwindSafe for UnsafeCell<T> {} diff --git a/src/libstd/process.rs b/src/libstd/process.rs index c19ece6a314..35c33f40253 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -10,25 +10,66 @@ //! A module for working with processes. //! -//! # Examples +//! This module is mostly concerned with spawning and interacting with child +//! processes, but it also provides [`abort`] and [`exit`] for terminating the +//! current process. //! -//! Basic usage where we try to execute the `cat` shell command: +//! # Spawning a process //! -//! ```should_panic +//! The [`Command`] struct is used to configure and spawn processes: +//! +//! ``` //! use std::process::Command; //! -//! let mut child = Command::new("/bin/cat") -//! .arg("file.txt") -//! .spawn() -//! .expect("failed to execute child"); +//! let output = Command::new("echo") +//! .arg("Hello world") +//! .output() +//! .expect("Failed to execute command"); +//! +//! assert_eq!(b"Hello world\n", output.stdout.as_slice()); +//! ``` +//! +//! Several methods on [`Command`], such as [`spawn`] or [`output`], can be used +//! to spawn a process. In particular, [`output`] spawns the child process and +//! waits until the process terminates, while [`spawn`] will return a [`Child`] +//! that represents the spawned child process. +//! +//! # Handling I/O +//! +//! The [`stdout`], [`stdin`], and [`stderr`] of a child process can be +//! configured by passing an [`Stdio`] to the corresponding method on +//! [`Command`]. Once spawned, they can be accessed from the [`Child`]. For +//! example, piping output from one command into another command can be done +//! like so: +//! +//! ```no_run +//! use std::process::{Command, Stdio}; //! -//! let ecode = child.wait() -//! .expect("failed to wait on child"); +//! // stdout must be configured with `Stdio::piped` in order to use +//! // `echo_child.stdout` +//! let echo_child = Command::new("echo") +//! .arg("Oh no, a tpyo!") +//! .stdout(Stdio::piped()) +//! .spawn() +//! .expect("Failed to start echo process"); +//! +//! // Note that `echo_child` is moved here, but we won't be needing +//! // `echo_child` anymore +//! let echo_out = echo_child.stdout.expect("Failed to open echo stdout"); +//! +//! let mut sed_child = Command::new("sed") +//! .arg("s/tpyo/typo/") +//! .stdin(Stdio::from(echo_out)) +//! .stdout(Stdio::piped()) +//! .spawn() +//! .expect("Failed to start sed process"); //! -//! assert!(ecode.success()); +//! let output = sed_child.wait_with_output().expect("Failed to wait on sed"); +//! assert_eq!(b"Oh no, a typo!\n", output.stdout.as_slice()); //! ``` //! -//! Calling a command with input and reading its output: +//! Note that [`ChildStderr`] and [`ChildStdout`] implement [`Write`] and +//! [`ChildStdin`] implements [`Read`]: //! //! ```no_run //! use std::process::{Command, Stdio}; @@ -52,6 +93,26 @@ //! //! assert_eq!(b"test", output.stdout.as_slice()); //! ``` +//! +//! [`abort`]: fn.abort.html +//! [`exit`]: fn.exit.html +//! +//! [`Command`]: struct.Command.html +//! [`spawn`]: struct.Command.html#method.spawn +//! [`output`]: struct.Command.html#method.output +//! +//! [`Child`]: struct.Child.html +//! [`ChildStdin`]: struct.ChildStdin.html +//! [`ChildStdout`]: struct.ChildStdout.html +//! [`ChildStderr`]: struct.ChildStderr.html +//! [`Stdio`]: struct.Stdio.html +//! +//! [`stdout`]: struct.Command.html#method.stdout +//! [`stdin`]: struct.Command.html#method.stdin +//! [`stderr`]: struct.Command.html#method.stderr +//! +//! [`Write`]: ../io/trait.Write.html +//! [`Read`]: ../io/trait.Read.html #![stable(feature = "process", since = "1.0.0")] diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index 5c49d6b5845..5555f364e6e 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -82,7 +82,7 @@ pub struct RwLock<T: ?Sized> { } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<T: ?Sized + Send + Sync> Send for RwLock<T> {} +unsafe impl<T: ?Sized + Send> Send for RwLock<T> {} #[stable(feature = "rust1", since = "1.0.0")] unsafe impl<T: ?Sized + Send + Sync> Sync for RwLock<T> {} diff --git a/src/libstd/sys/unix/ext/mod.rs b/src/libstd/sys/unix/ext/mod.rs index 98bc90dd4e1..c221f7c8cfe 100644 --- a/src/libstd/sys/unix/ext/mod.rs +++ b/src/libstd/sys/unix/ext/mod.rs @@ -10,8 +10,14 @@ //! Experimental extensions to `std` for Unix platforms. //! -//! For now, this module is limited to extracting file descriptors, -//! but its functionality will grow over time. +//! Provides access to platform-level information on Unix platforms, and +//! exposes Unix-specific functions that would otherwise be inappropriate as +//! part of the core `std` library. +//! +//! It exposes more ways to deal with platform-specific strings (`OsStr`, +//! `OsString`), allows to set permissions more granularly, extract low-level +//! file descriptors from files and sockets, and has platform-specific helpers +//! for spawning processes. //! //! # Examples //! diff --git a/src/libstd/sys/unix/rand.rs b/src/libstd/sys/unix/rand.rs index fd066c9cdbe..e2d40742c71 100644 --- a/src/libstd/sys/unix/rand.rs +++ b/src/libstd/sys/unix/rand.rs @@ -49,7 +49,9 @@ mod imp { target_arch = "powerpc64", target_arch = "s390x")))] fn getrandom(buf: &mut [u8]) -> libc::c_long { - #[cfg(target_arch = "x86_64")] + #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] + const NR_GETRANDOM: libc::c_long = 0x40000000 + 318; + #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] const NR_GETRANDOM: libc::c_long = 318; #[cfg(target_arch = "x86")] const NR_GETRANDOM: libc::c_long = 355; |
