Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 25 pull requests #35321

Closed
wants to merge 64 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
e805cb6
Add io::Error doc examples
GuillaumeGomez Jul 29, 2016
aad5f6f
Add doc example for io::Stderr
GuillaumeGomez Jul 29, 2016
451683f
Add doc example for Stdin
GuillaumeGomez Jul 29, 2016
aeb3af8
Add doc example for Stdout
GuillaumeGomez Jul 29, 2016
76026d1
Fix grammar verification
dns2utf8 Jul 23, 2016
2bed205
Add io::Take doc example
GuillaumeGomez Jul 30, 2016
fda473f
Add urls in std::io types
GuillaumeGomez Jul 30, 2016
b77b9b7
Provide more explicit example of wildcard version in guessing game doc.
jongiddy Jul 31, 2016
65e3ff4
add extended information for E0529, slice pattern expects array or slice
zackmdavis Jun 17, 2016
7093d1d
add extended info for E0527, slice pattern element count expectations
zackmdavis Jun 17, 2016
e960021
extended info for E0528, expected at least this-and-such many elements
zackmdavis Jun 17, 2016
cede35e
Merge guidelines from RFC 1567 into UX Guidelines.
Havvy Jul 17, 2016
157f7c1
Add Derive not possible question to Copy
Havvy Jul 26, 2016
57e3b9e
Indicate where the `std::net::Incoming` struct is created.
frewsxcv Aug 2, 2016
f2d8db1
Link to relevant method/struct for `std::net::Shutdown` docs.
frewsxcv Aug 2, 2016
3081dd8
Add doc example for `std::ffi::NulError::nul_position`.
frewsxcv Aug 2, 2016
727d929
Add doc examples for `range::RangeArgument::{start,end}`.
frewsxcv Jul 26, 2016
1fa9b8d
Add doc example for Vec
GuillaumeGomez Aug 2, 2016
d90c166
Update the-stack-and-the-heap.md
mLuby Aug 2, 2016
3e46c9d
Add doc examples for FileType struct
GuillaumeGomez Jul 27, 2016
d603892
Add span method for hir::Generics struct
GuillaumeGomez Aug 3, 2016
9b690c9
Update E0132 to new format
GuillaumeGomez Aug 3, 2016
4fc6f5a
Add an example to `std::thread::park_timeout`
dns2utf8 Aug 3, 2016
20721a4
Add link to replacement function
dns2utf8 Aug 3, 2016
1607d5b
Add note test for E0132
GuillaumeGomez Aug 3, 2016
c89e278
Update error message for E0109
circuitfox Aug 3, 2016
33a4806
Clean up `std::raw` docs
apasel422 Aug 4, 2016
6131815
Fixes for issues #35215 and #35216
leikahing Aug 4, 2016
0e75684
Tidying up some of the line spacing / code formatting for NOTE/ERROR …
leikahing Aug 4, 2016
ded0d51
Removing trailing whitespace leftover from last re-formatting commit
leikahing Aug 4, 2016
7fc0b2f
Update E0079 to new format
Aug 4, 2016
ee8d6b0
Update error message for E0172
Aug 4, 2016
08ff7a8
Update error message E0178
Aug 4, 2016
eeda69f
Set label for unreachable pattern
saml Aug 4, 2016
034e659
Changing label to "this is an..."
saml Aug 4, 2016
7c58b26
Updated E0071 to new format.
razielgn Aug 3, 2016
5430e55
E0110 update error format
circuitfox Aug 4, 2016
4492838
Update error message E0120
Aug 4, 2016
a0bdb17
Update E0124 to the new error format
sciyoshi Aug 4, 2016
f52bf09
Rollup merge of #34319 - zackmdavis:explain_slice_pattern_errors, r=G…
steveklabnik Aug 4, 2016
30e2581
Rollup merge of #34894 - Havvy:patch-2, r=steveklabnik
steveklabnik Aug 4, 2016
9d57bd0
Rollup merge of #34994 - dns2utf8:doc_grammar, r=steveklabnik
steveklabnik Aug 4, 2016
7f559d4
Rollup merge of #35041 - frewsxcv:range-rangeargument, r=GuillaumeGomez
steveklabnik Aug 4, 2016
f301a92
Rollup merge of #35042 - Havvy:copy_error_doc, r=GuillaumeGomez
steveklabnik Aug 4, 2016
3f87e78
Rollup merge of #35076 - GuillaumeGomez:file_type_docs, r=steveklabnik
steveklabnik Aug 4, 2016
d6af812
Rollup merge of #35109 - GuillaumeGomez:io_docs, r=steveklabnik
steveklabnik Aug 4, 2016
ccf4fbf
Rollup merge of #35137 - jongiddy:explicit-wildcard, r=steveklabnik
steveklabnik Aug 4, 2016
707a291
Rollup merge of #35175 - frewsxcv:tcp, r=GuillaumeGomez
steveklabnik Aug 4, 2016
9ddde2c
Rollup merge of #35181 - GuillaumeGomez:vec_doc, r=steveklabnik
steveklabnik Aug 4, 2016
01562a1
Rollup merge of #35182 - frewsxcv:nulerror, r=steveklabnik
steveklabnik Aug 4, 2016
46f4682
Rollup merge of #35189 - mLuby:patch-1, r=steveklabnik
steveklabnik Aug 4, 2016
540451f
Rollup merge of #35239 - dns2utf8:doc_park_timeout, r=steveklabnik
steveklabnik Aug 4, 2016
1a0a919
Rollup merge of #35264 - GuillaumeGomez:E0132_update, r=jonathandturner
steveklabnik Aug 4, 2016
36a1560
Rollup merge of #35266 - circuitfox:35247-E0109-update-error-format, …
steveklabnik Aug 4, 2016
361d9b4
Rollup merge of #35281 - apasel422:repr, r=steveklabnik
steveklabnik Aug 4, 2016
e70b1ba
Rollup merge of #35285 - razielgn:updated-e0071-to-new-format, r=jona…
steveklabnik Aug 4, 2016
7188c3e
Rollup merge of #35289 - birryree:E0060_E0061_format_update, r=jonath…
steveklabnik Aug 4, 2016
fc24283
Rollup merge of #35291 - yossi-k:master, r=jonathandturner
steveklabnik Aug 4, 2016
423aa39
Rollup merge of #35294 - Roybie:35272-E0172-update-error-format, r=jo…
steveklabnik Aug 4, 2016
bf4d779
Rollup merge of #35296 - medzin:master, r=jonathandturner
steveklabnik Aug 4, 2016
ef18466
Rollup merge of #35297 - saml:e0001-label, r=jonathandturner
steveklabnik Aug 4, 2016
3d9003d
Rollup merge of #35298 - Keats:err-120, r=jonathandturner
steveklabnik Aug 4, 2016
59a2293
Rollup merge of #35299 - circuitfox:E0110-update-error-format, r=jona…
steveklabnik Aug 4, 2016
60c1910
Rollup merge of #35318 - sciyoshi:update-e0124, r=jonathandturner
steveklabnik Aug 4, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 152 additions & 1 deletion src/libstd/io/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ pub type Result<T> = result::Result<T, Error>;
///
/// Errors mostly originate from the underlying OS, but custom instances of
/// `Error` can be created with crafted error messages and a particular value of
/// `ErrorKind`.
/// [`ErrorKind`].
///
/// [`ErrorKind`]: enum.ErrorKind.html
#[derive(Debug)]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Error {
Expand All @@ -77,6 +79,10 @@ struct Custom {
///
/// This list is intended to grow over time and it is not recommended to
/// exhaustively match against it.
///
/// It is used with the [`io::Error`] type.
///
/// [`io::Error`]: struct.Error.html
#[derive(Copy, PartialEq, Eq, Clone, Debug)]
#[stable(feature = "rust1", since = "1.0.0")]
#[allow(deprecated)]
Expand Down Expand Up @@ -208,6 +214,14 @@ impl Error {
/// This function reads the value of `errno` for the target platform (e.g.
/// `GetLastError` on Windows) and will return a corresponding instance of
/// `Error` for the error code.
///
/// # Examples
///
/// ```
/// use std::io::Error;
///
/// println!("last OS error: {:?}", Error::last_os_error());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn last_os_error() -> Error {
Error::from_raw_os_error(sys::os::errno() as i32)
Expand Down Expand Up @@ -248,6 +262,27 @@ impl Error {
/// If this `Error` was constructed via `last_os_error` or
/// `from_raw_os_error`, then this function will return `Some`, otherwise
/// it will return `None`.
///
/// # Examples
///
/// ```
/// use std::io::{Error, ErrorKind};
///
/// fn print_os_error(err: &Error) {
/// if let Some(raw_os_err) = err.raw_os_error() {
/// println!("raw OS error: {:?}", raw_os_err);
/// } else {
/// println!("Not an OS error");
/// }
/// }
///
/// fn main() {
/// // Will print "raw OS error: ...".
/// print_os_error(&Error::last_os_error());
/// // Will print "Not an OS error".
/// print_os_error(&Error::new(ErrorKind::Other, "oh no!"));
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn raw_os_error(&self) -> Option<i32> {
match self.repr {
Expand All @@ -260,6 +295,27 @@ impl Error {
///
/// If this `Error` was constructed via `new` then this function will
/// return `Some`, otherwise it will return `None`.
///
/// # Examples
///
/// ```
/// use std::io::{Error, ErrorKind};
///
/// fn print_error(err: &Error) {
/// if let Some(inner_err) = err.get_ref() {
/// println!("Inner error: {:?}", inner_err);
/// } else {
/// println!("No inner error");
/// }
/// }
///
/// fn main() {
/// // Will print "No inner error".
/// print_error(&Error::last_os_error());
/// // Will print "Inner error: ...".
/// print_error(&Error::new(ErrorKind::Other, "oh no!"));
/// }
/// ```
#[stable(feature = "io_error_inner", since = "1.3.0")]
pub fn get_ref(&self) -> Option<&(error::Error+Send+Sync+'static)> {
match self.repr {
Expand All @@ -273,6 +329,63 @@ impl Error {
///
/// If this `Error` was constructed via `new` then this function will
/// return `Some`, otherwise it will return `None`.
///
/// # Examples
///
/// ```
/// use std::io::{Error, ErrorKind};
/// use std::{error, fmt};
/// use std::fmt::Display;
///
/// #[derive(Debug)]
/// struct MyError {
/// v: String,
/// }
///
/// impl MyError {
/// fn new() -> MyError {
/// MyError {
/// v: "oh no!".to_owned()
/// }
/// }
///
/// fn change_message(&mut self, new_message: &str) {
/// self.v = new_message.to_owned();
/// }
/// }
///
/// impl error::Error for MyError {
/// fn description(&self) -> &str { &self.v }
/// }
///
/// impl Display for MyError {
/// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
/// write!(f, "MyError: {}", &self.v)
/// }
/// }
///
/// fn change_error(mut err: Error) -> Error {
/// if let Some(inner_err) = err.get_mut() {
/// inner_err.downcast_mut::<MyError>().unwrap().change_message("I've been changed!");
/// }
/// err
/// }
///
/// fn print_error(err: &Error) {
/// if let Some(inner_err) = err.get_ref() {
/// println!("Inner error: {}", inner_err);
/// } else {
/// println!("No inner error");
/// }
/// }
///
/// fn main() {
/// // Will print "No inner error".
/// print_error(&change_error(Error::last_os_error()));
/// // Will print "Inner error: ...".
/// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new())));
/// }
/// ```
#[stable(feature = "io_error_inner", since = "1.3.0")]
pub fn get_mut(&mut self) -> Option<&mut (error::Error+Send+Sync+'static)> {
match self.repr {
Expand All @@ -285,6 +398,27 @@ impl Error {
///
/// If this `Error` was constructed via `new` then this function will
/// return `Some`, otherwise it will return `None`.
///
/// # Examples
///
/// ```
/// use std::io::{Error, ErrorKind};
///
/// fn print_error(err: Error) {
/// if let Some(inner_err) = err.into_inner() {
/// println!("Inner error: {}", inner_err);
/// } else {
/// println!("No inner error");
/// }
/// }
///
/// fn main() {
/// // Will print "No inner error".
/// print_error(Error::last_os_error());
/// // Will print "Inner error: ...".
/// print_error(Error::new(ErrorKind::Other, "oh no!"));
/// }
/// ```
#[stable(feature = "io_error_inner", since = "1.3.0")]
pub fn into_inner(self) -> Option<Box<error::Error+Send+Sync>> {
match self.repr {
Expand All @@ -294,6 +428,23 @@ impl Error {
}

/// Returns the corresponding `ErrorKind` for this error.
///
/// # Examples
///
/// ```
/// use std::io::{Error, ErrorKind};
///
/// fn print_error(err: Error) {
/// println!("{:?}", err.kind());
/// }
///
/// fn main() {
/// // Will print "No inner error".
/// print_error(Error::last_os_error());
/// // Will print "Inner error: ...".
/// print_error(Error::new(ErrorKind::AddrInUse, "oh no!"));
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn kind(&self) -> ErrorKind {
match self.repr {
Expand Down
26 changes: 25 additions & 1 deletion src/libstd/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1082,16 +1082,22 @@ pub trait Seek {
///
/// If the seek operation completed successfully,
/// this method returns the new position from the start of the stream.
/// That position can be used later with `SeekFrom::Start`.
/// That position can be used later with [`SeekFrom::Start`].
///
/// # Errors
///
/// Seeking to a negative offset is considered an error.
///
/// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start
#[stable(feature = "rust1", since = "1.0.0")]
fn seek(&mut self, pos: SeekFrom) -> Result<u64>;
}

/// Enumeration of possible methods to seek within an I/O object.
///
/// It is used by the [`Seek`] trait.
///
/// [`Seek`]: trait.Seek.html
#[derive(Copy, PartialEq, Eq, Clone, Debug)]
#[stable(feature = "rust1", since = "1.0.0")]
pub enum SeekFrom {
Expand Down Expand Up @@ -1482,6 +1488,24 @@ impl<T> Take<T> {
///
/// This instance may reach EOF after reading fewer bytes than indicated by
/// this method if the underlying `Read` instance reaches EOF.
///
/// # Examples
///
/// ```
/// use std::io;
/// use std::io::prelude::*;
/// use std::fs::File;
///
/// # fn foo() -> io::Result<()> {
/// let f = try!(File::open("foo.txt"));
///
/// // read at most five bytes
/// let handle = f.take(5);
///
/// println!("limit: {}", handle.limit());
/// # Ok(())
/// # }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn limit(&self) -> u64 { self.limit }
}
Expand Down
45 changes: 45 additions & 0 deletions src/libstd/io/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,21 @@ impl Stdin {
///
/// [`Read`]: trait.Read.html
/// [`BufRead`]: trait.BufRead.html
///
/// # Examples
///
/// ```
/// use std::io::{self, Read};
///
/// # fn foo() -> io::Result<String> {
/// let mut buffer = String::new();
/// let stdin = io::stdin();
/// let mut handle = stdin.lock();
///
/// try!(handle.read_to_string(&mut buffer));
/// # Ok(buffer)
/// # }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn lock(&self) -> StdinLock {
StdinLock { inner: self.inner.lock().unwrap_or_else(|e| e.into_inner()) }
Expand Down Expand Up @@ -399,6 +414,21 @@ impl Stdout {
///
/// The lock is released when the returned lock goes out of scope. The
/// returned guard also implements the `Write` trait for writing data.
///
/// # Examples
///
/// ```
/// use std::io::{self, Write};
///
/// # fn foo() -> io::Result<()> {
/// let stdout = io::stdout();
/// let mut handle = stdout.lock();
///
/// try!(handle.write(b"hello world"));
///
/// # Ok(())
/// # }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn lock(&self) -> StdoutLock {
StdoutLock { inner: self.inner.lock().unwrap_or_else(|e| e.into_inner()) }
Expand Down Expand Up @@ -505,6 +535,21 @@ impl Stderr {
///
/// The lock is released when the returned lock goes out of scope. The
/// returned guard also implements the `Write` trait for writing data.
///
/// # Examples
///
/// ```
/// use std::io::{self, Write};
///
/// fn foo() -> io::Result<()> {
/// let stderr = io::stderr();
/// let mut handle = stderr.lock();
///
/// try!(handle.write(b"hello world"));
///
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn lock(&self) -> StderrLock {
StderrLock { inner: self.inner.lock().unwrap_or_else(|e| e.into_inner()) }
Expand Down