Auto merge of #49357 - frewsxcv:frewsxcv-termination-doc-examples, r=GuillaumeGomez

Remove hidden `foo` functions from doc examples; use `Termination` trait.

Fixes https://github.com/rust-lang/rust/issues/49233.

Easier to review with the white-space ignoring `?w=1` feature: https://github.com/rust-lang/rust/pull/49357/files?w=1
This commit is contained in:
bors 2018-03-28 18:11:44 +00:00
commit e5277c1457
13 changed files with 1129 additions and 1126 deletions

View File

@ -552,17 +552,17 @@ pub fn home_dir() -> Option<PathBuf> {
///
/// [msdn]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa364992(v=vs.85).aspx
///
/// ```
/// ```no_run
/// use std::env;
/// use std::fs::File;
///
/// # fn foo() -> std::io::Result<()> {
/// let mut dir = env::temp_dir();
/// dir.push("foo.txt");
/// fn main() -> std::io::Result<()> {
/// let mut dir = env::temp_dir();
/// dir.push("foo.txt");
///
/// let f = File::create(dir)?;
/// # Ok(())
/// # }
/// let f = File::create(dir)?;
/// Ok(())
/// }
/// ```
#[stable(feature = "env", since = "1.0.0")]
pub fn temp_dir() -> PathBuf {

View File

@ -41,11 +41,11 @@ use time::SystemTime;
/// use std::fs::File;
/// use std::io::prelude::*;
///
/// # fn foo() -> std::io::Result<()> {
/// let mut file = File::create("foo.txt")?;
/// file.write_all(b"Hello, world!")?;
/// # Ok(())
/// # }
/// fn main() -> std::io::Result<()> {
/// let mut file = File::create("foo.txt")?;
/// file.write_all(b"Hello, world!")?;
/// Ok(())
/// }
/// ```
///
/// Read the contents of a file into a [`String`]:
@ -54,13 +54,13 @@ use time::SystemTime;
/// use std::fs::File;
/// use std::io::prelude::*;
///
/// # fn foo() -> std::io::Result<()> {
/// let mut file = File::open("foo.txt")?;
/// let mut contents = String::new();
/// file.read_to_string(&mut contents)?;
/// assert_eq!(contents, "Hello, world!");
/// # Ok(())
/// # }
/// fn main() -> std::io::Result<()> {
/// let mut file = File::open("foo.txt")?;
/// let mut contents = String::new();
/// file.read_to_string(&mut contents)?;
/// assert_eq!(contents, "Hello, world!");
/// Ok(())
/// }
/// ```
///
/// It can be more efficient to read the contents of a file with a buffered
@ -71,14 +71,14 @@ use time::SystemTime;
/// use std::io::BufReader;
/// use std::io::prelude::*;
///
/// # fn foo() -> std::io::Result<()> {
/// let file = File::open("foo.txt")?;
/// let mut buf_reader = BufReader::new(file);
/// let mut contents = String::new();
/// buf_reader.read_to_string(&mut contents)?;
/// assert_eq!(contents, "Hello, world!");
/// # Ok(())
/// # }
/// fn main() -> std::io::Result<()> {
/// let file = File::open("foo.txt")?;
/// let mut buf_reader = BufReader::new(file);
/// let mut contents = String::new();
/// buf_reader.read_to_string(&mut contents)?;
/// assert_eq!(contents, "Hello, world!");
/// Ok(())
/// }
/// ```
///
/// Note that, although read and write methods require a `&mut File`, because
@ -256,10 +256,10 @@ fn initial_buffer_size(file: &File) -> usize {
/// use std::fs;
/// use std::net::SocketAddr;
///
/// # fn foo() -> Result<(), Box<std::error::Error + 'static>> {
/// let foo: SocketAddr = String::from_utf8_lossy(&fs::read("address.txt")?).parse()?;
/// # Ok(())
/// # }
/// fn main() -> Result<(), Box<std::error::Error + 'static>> {
/// let foo: SocketAddr = String::from_utf8_lossy(&fs::read("address.txt")?).parse()?;
/// Ok(())
/// }
/// ```
#[unstable(feature = "fs_read_write", issue = "46588")]
pub fn read<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
@ -298,10 +298,10 @@ pub fn read<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
/// use std::fs;
/// use std::net::SocketAddr;
///
/// # fn foo() -> Result<(), Box<std::error::Error + 'static>> {
/// let foo: SocketAddr = fs::read_string("address.txt")?.parse()?;
/// # Ok(())
/// # }
/// fn main() -> Result<(), Box<std::error::Error + 'static>> {
/// let foo: SocketAddr = fs::read_string("address.txt")?.parse()?;
/// Ok(())
/// }
/// ```
#[unstable(feature = "fs_read_write", issue = "46588")]
pub fn read_string<P: AsRef<Path>>(path: P) -> io::Result<String> {
@ -329,10 +329,10 @@ pub fn read_string<P: AsRef<Path>>(path: P) -> io::Result<String> {
///
/// use std::fs;
///
/// # fn foo() -> std::io::Result<()> {
/// fs::write("foo.txt", b"Lorem ipsum")?;
/// # Ok(())
/// # }
/// fn main() -> std::io::Result<()> {
/// fs::write("foo.txt", b"Lorem ipsum")?;
/// Ok(())
/// }
/// ```
#[unstable(feature = "fs_read_write", issue = "46588")]
pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> io::Result<()> {
@ -356,7 +356,7 @@ impl File {
/// ```no_run
/// use std::fs::File;
///
/// # fn foo() -> std::io::Result<()> {
/// fn main() -> std::io::Result<()> {
/// let mut f = File::open("foo.txt")?;
/// # Ok(())
/// # }
@ -380,10 +380,10 @@ impl File {
/// ```no_run
/// use std::fs::File;
///
/// # fn foo() -> std::io::Result<()> {
/// let mut f = File::create("foo.txt")?;
/// # Ok(())
/// # }
/// fn main() -> std::io::Result<()> {
/// let mut f = File::create("foo.txt")?;
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn create<P: AsRef<Path>>(path: P) -> io::Result<File> {
@ -401,13 +401,13 @@ impl File {
/// use std::fs::File;
/// use std::io::prelude::*;
///
/// # fn foo() -> std::io::Result<()> {
/// let mut f = File::create("foo.txt")?;
/// f.write_all(b"Hello, world!")?;
/// fn main() -> std::io::Result<()> {
/// let mut f = File::create("foo.txt")?;
/// f.write_all(b"Hello, world!")?;
///
/// f.sync_all()?;
/// # Ok(())
/// # }
/// f.sync_all()?;
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn sync_all(&self) -> io::Result<()> {
@ -432,13 +432,13 @@ impl File {
/// use std::fs::File;
/// use std::io::prelude::*;
///
/// # fn foo() -> std::io::Result<()> {
/// let mut f = File::create("foo.txt")?;
/// f.write_all(b"Hello, world!")?;
/// fn main() -> std::io::Result<()> {
/// let mut f = File::create("foo.txt")?;
/// f.write_all(b"Hello, world!")?;
///
/// f.sync_data()?;
/// # Ok(())
/// # }
/// f.sync_data()?;
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn sync_data(&self) -> io::Result<()> {
@ -466,11 +466,11 @@ impl File {
/// ```no_run
/// use std::fs::File;
///
/// # fn foo() -> std::io::Result<()> {
/// let mut f = File::create("foo.txt")?;
/// f.set_len(10)?;
/// # Ok(())
/// # }
/// fn main() -> std::io::Result<()> {
/// let mut f = File::create("foo.txt")?;
/// f.set_len(10)?;
/// Ok(())
/// }
/// ```
///
/// Note that this method alters the content of the underlying file, even
@ -487,11 +487,11 @@ impl File {
/// ```no_run
/// use std::fs::File;
///
/// # fn foo() -> std::io::Result<()> {
/// let mut f = File::open("foo.txt")?;
/// let metadata = f.metadata()?;
/// # Ok(())
/// # }
/// fn main() -> std::io::Result<()> {
/// let mut f = File::open("foo.txt")?;
/// let metadata = f.metadata()?;
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn metadata(&self) -> io::Result<Metadata> {
@ -509,11 +509,11 @@ impl File {
/// ```no_run
/// use std::fs::File;
///
/// # fn foo() -> std::io::Result<()> {
/// let mut file = File::open("foo.txt")?;
/// let file_copy = file.try_clone()?;
/// # Ok(())
/// # }
/// fn main() -> std::io::Result<()> {
/// let mut file = File::open("foo.txt")?;
/// let file_copy = file.try_clone()?;
/// Ok(())
/// }
/// ```
///
/// Assuming theres a file named `foo.txt` with contents `abcdef\n`, create
@ -525,17 +525,17 @@ impl File {
/// use std::io::SeekFrom;
/// use std::io::prelude::*;
///
/// # fn foo() -> std::io::Result<()> {
/// let mut file = File::open("foo.txt")?;
/// let mut file_copy = file.try_clone()?;
/// fn main() -> std::io::Result<()> {
/// let mut file = File::open("foo.txt")?;
/// let mut file_copy = file.try_clone()?;
///
/// file.seek(SeekFrom::Start(3))?;
/// file.seek(SeekFrom::Start(3))?;
///
/// let mut contents = vec![];
/// file_copy.read_to_end(&mut contents)?;
/// assert_eq!(contents, b"def\n");
/// # Ok(())
/// # }
/// let mut contents = vec![];
/// file_copy.read_to_end(&mut contents)?;
/// assert_eq!(contents, b"def\n");
/// Ok(())
/// }
/// ```
#[stable(feature = "file_try_clone", since = "1.9.0")]
pub fn try_clone(&self) -> io::Result<File> {
@ -562,16 +562,16 @@ impl File {
///
/// # Examples
///
/// ```
/// # fn foo() -> std::io::Result<()> {
/// use std::fs::File;
/// ```no_run
/// fn main() -> std::io::Result<()> {
/// use std::fs::File;
///
/// let file = File::open("foo.txt")?;
/// let mut perms = file.metadata()?.permissions();
/// perms.set_readonly(true);
/// file.set_permissions(perms)?;
/// # Ok(())
/// # }
/// let file = File::open("foo.txt")?;
/// let mut perms = file.metadata()?.permissions();
/// perms.set_readonly(true);
/// file.set_permissions(perms)?;
/// Ok(())
/// }
/// ```
///
/// Note that this method alters the permissions of the underlying file,
@ -891,15 +891,15 @@ impl Metadata {
///
/// # Examples
///
/// ```
/// # fn foo() -> std::io::Result<()> {
/// use std::fs;
/// ```no_run
/// fn main() -> std::io::Result<()> {
/// use std::fs;
///
/// let metadata = fs::metadata("foo.txt")?;
/// let metadata = fs::metadata("foo.txt")?;
///
/// println!("{:?}", metadata.file_type());
/// # Ok(())
/// # }
/// println!("{:?}", metadata.file_type());
/// Ok(())
/// }
/// ```
#[stable(feature = "file_type", since = "1.1.0")]
pub fn file_type(&self) -> FileType {
@ -916,15 +916,15 @@ impl Metadata {
///
/// # Examples
///
/// ```
/// # fn foo() -> std::io::Result<()> {
/// use std::fs;
/// ```no_run
/// fn main() -> std::io::Result<()> {
/// use std::fs;
///
/// let metadata = fs::metadata("foo.txt")?;
/// let metadata = fs::metadata("foo.txt")?;
///
/// assert!(!metadata.is_dir());
/// # Ok(())
/// # }
/// assert!(!metadata.is_dir());
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_dir(&self) -> bool { self.file_type().is_dir() }
@ -939,15 +939,15 @@ impl Metadata {
///
/// # Examples
///
/// ```
/// # fn foo() -> std::io::Result<()> {
/// ```no_run
/// use std::fs;
///
/// let metadata = fs::metadata("foo.txt")?;
/// fn main() -> std::io::Result<()> {
/// let metadata = fs::metadata("foo.txt")?;
///
/// assert!(metadata.is_file());
/// # Ok(())
/// # }
/// assert!(metadata.is_file());
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_file(&self) -> bool { self.file_type().is_file() }
@ -956,15 +956,15 @@ impl Metadata {
///
/// # Examples
///
/// ```
/// # fn foo() -> std::io::Result<()> {
/// ```no_run
/// use std::fs;
///
/// let metadata = fs::metadata("foo.txt")?;
/// fn main() -> std::io::Result<()> {
/// let metadata = fs::metadata("foo.txt")?;
///
/// assert_eq!(0, metadata.len());
/// # Ok(())
/// # }
/// assert_eq!(0, metadata.len());
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn len(&self) -> u64 { self.0.size() }
@ -973,15 +973,15 @@ impl Metadata {
///
/// # Examples
///
/// ```
/// # fn foo() -> std::io::Result<()> {
/// ```no_run
/// use std::fs;
///
/// let metadata = fs::metadata("foo.txt")?;
/// fn main() -> std::io::Result<()> {
/// let metadata = fs::metadata("foo.txt")?;
///
/// assert!(!metadata.permissions().readonly());
/// # Ok(())
/// # }
/// assert!(!metadata.permissions().readonly());
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn permissions(&self) -> Permissions {
@ -1000,19 +1000,19 @@ impl Metadata {
///
/// # Examples
///
/// ```
/// # fn foo() -> std::io::Result<()> {
/// ```no_run
/// use std::fs;
///
/// let metadata = fs::metadata("foo.txt")?;
/// fn main() -> std::io::Result<()> {
/// let metadata = fs::metadata("foo.txt")?;
///
/// if let Ok(time) = metadata.modified() {
/// println!("{:?}", time);
/// } else {
/// println!("Not supported on this platform");
/// if let Ok(time) = metadata.modified() {
/// println!("{:?}", time);
/// } else {
/// println!("Not supported on this platform");
/// }
/// Ok(())
/// }
/// # Ok(())
/// # }
/// ```
#[stable(feature = "fs_time", since = "1.10.0")]
pub fn modified(&self) -> io::Result<SystemTime> {
@ -1035,19 +1035,19 @@ impl Metadata {
///
/// # Examples
///
/// ```
/// # fn foo() -> std::io::Result<()> {
/// ```no_run
/// use std::fs;
///
/// let metadata = fs::metadata("foo.txt")?;
/// fn main() -> std::io::Result<()> {
/// let metadata = fs::metadata("foo.txt")?;
///
/// if let Ok(time) = metadata.accessed() {
/// println!("{:?}", time);
/// } else {
/// println!("Not supported on this platform");
/// if let Ok(time) = metadata.accessed() {
/// println!("{:?}", time);
/// } else {
/// println!("Not supported on this platform");
/// }
/// Ok(())
/// }
/// # Ok(())
/// # }
/// ```
#[stable(feature = "fs_time", since = "1.10.0")]
pub fn accessed(&self) -> io::Result<SystemTime> {
@ -1066,19 +1066,19 @@ impl Metadata {
///
/// # Examples
///
/// ```
/// # fn foo() -> std::io::Result<()> {
/// ```no_run
/// use std::fs;
///
/// let metadata = fs::metadata("foo.txt")?;
/// fn main() -> std::io::Result<()> {
/// let metadata = fs::metadata("foo.txt")?;
///
/// if let Ok(time) = metadata.created() {
/// println!("{:?}", time);
/// } else {
/// println!("Not supported on this platform");
/// if let Ok(time) = metadata.created() {
/// println!("{:?}", time);
/// } else {
/// println!("Not supported on this platform");
/// }
/// Ok(())
/// }
/// # Ok(())
/// # }
/// ```
#[stable(feature = "fs_time", since = "1.10.0")]
pub fn created(&self) -> io::Result<SystemTime> {
@ -1110,16 +1110,16 @@ impl Permissions {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs::File;
///
/// # fn foo() -> std::io::Result<()> {
/// let mut f = File::create("foo.txt")?;
/// let metadata = f.metadata()?;
/// fn main() -> std::io::Result<()> {
/// let mut f = File::create("foo.txt")?;
/// let metadata = f.metadata()?;
///
/// assert_eq!(false, metadata.permissions().readonly());
/// # Ok(())
/// # }
/// assert_eq!(false, metadata.permissions().readonly());
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn readonly(&self) -> bool { self.0.readonly() }
@ -1135,23 +1135,23 @@ impl Permissions {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs::File;
///
/// # fn foo() -> std::io::Result<()> {
/// let f = File::create("foo.txt")?;
/// let metadata = f.metadata()?;
/// let mut permissions = metadata.permissions();
/// fn main() -> std::io::Result<()> {
/// let f = File::create("foo.txt")?;
/// let metadata = f.metadata()?;
/// let mut permissions = metadata.permissions();
///
/// permissions.set_readonly(true);
/// permissions.set_readonly(true);
///
/// // filesystem doesn't change
/// assert_eq!(false, metadata.permissions().readonly());
/// // filesystem doesn't change
/// assert_eq!(false, metadata.permissions().readonly());
///
/// // just this particular `permissions`.
/// assert_eq!(true, permissions.readonly());
/// # Ok(())
/// # }
/// // just this particular `permissions`.
/// assert_eq!(true, permissions.readonly());
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn set_readonly(&mut self, readonly: bool) {
@ -1170,16 +1170,16 @@ impl FileType {
///
/// # Examples
///
/// ```
/// # fn foo() -> std::io::Result<()> {
/// use std::fs;
/// ```no_run
/// fn main() -> std::io::Result<()> {
/// use std::fs;
///
/// let metadata = fs::metadata("foo.txt")?;
/// let file_type = metadata.file_type();
/// let metadata = fs::metadata("foo.txt")?;
/// let file_type = metadata.file_type();
///
/// assert_eq!(file_type.is_dir(), false);
/// # Ok(())
/// # }
/// assert_eq!(file_type.is_dir(), false);
/// Ok(())
/// }
/// ```
#[stable(feature = "file_type", since = "1.1.0")]
pub fn is_dir(&self) -> bool { self.0.is_dir() }
@ -1194,16 +1194,16 @@ impl FileType {
///
/// # Examples
///
/// ```
/// # fn foo() -> std::io::Result<()> {
/// use std::fs;
/// ```no_run
/// fn main() -> std::io::Result<()> {
/// use std::fs;
///
/// let metadata = fs::metadata("foo.txt")?;
/// let file_type = metadata.file_type();
/// let metadata = fs::metadata("foo.txt")?;
/// let file_type = metadata.file_type();
///
/// assert_eq!(file_type.is_file(), true);
/// # Ok(())
/// # }
/// assert_eq!(file_type.is_file(), true);
/// Ok(())
/// }
/// ```
#[stable(feature = "file_type", since = "1.1.0")]
pub fn is_file(&self) -> bool { self.0.is_file() }
@ -1228,16 +1228,16 @@ impl FileType {
///
/// # Examples
///
/// ```
/// # fn foo() -> std::io::Result<()> {
/// ```no_run
/// use std::fs;
///
/// let metadata = fs::symlink_metadata("foo.txt")?;
/// let file_type = metadata.file_type();
/// fn main() -> std::io::Result<()> {
/// let metadata = fs::symlink_metadata("foo.txt")?;
/// let file_type = metadata.file_type();
///
/// assert_eq!(file_type.is_symlink(), false);
/// # Ok(())
/// # }
/// assert_eq!(file_type.is_symlink(), false);
/// Ok(())
/// }
/// ```
#[stable(feature = "file_type", since = "1.1.0")]
pub fn is_symlink(&self) -> bool { self.0.is_symlink() }
@ -1274,15 +1274,16 @@ impl DirEntry {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
/// # fn foo() -> std::io::Result<()> {
/// for entry in fs::read_dir(".")? {
/// let dir = entry?;
/// println!("{:?}", dir.path());
///
/// fn main() -> std::io::Result<()> {
/// for entry in fs::read_dir(".")? {
/// let dir = entry?;
/// println!("{:?}", dir.path());
/// }
/// Ok(())
/// }
/// # Ok(())
/// # }
/// ```
///
/// This prints output like:
@ -1427,13 +1428,13 @@ impl AsInner<fs_imp::DirEntry> for DirEntry {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
///
/// # fn foo() -> std::io::Result<()> {
/// fs::remove_file("a.txt")?;
/// # Ok(())
/// # }
/// fn main() -> std::io::Result<()> {
/// fs::remove_file("a.txt")?;
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn remove_file<P: AsRef<Path>>(path: P) -> io::Result<()> {
@ -1464,14 +1465,14 @@ pub fn remove_file<P: AsRef<Path>>(path: P) -> io::Result<()> {
///
/// # Examples
///
/// ```rust
/// # fn foo() -> std::io::Result<()> {
/// ```rust,no_run
/// use std::fs;
///
/// let attr = fs::metadata("/some/file/path.txt")?;
/// // inspect attr ...
/// # Ok(())
/// # }
/// fn main() -> std::io::Result<()> {
/// let attr = fs::metadata("/some/file/path.txt")?;
/// // inspect attr ...
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> {
@ -1498,14 +1499,14 @@ pub fn metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> {
///
/// # Examples
///
/// ```rust
/// # fn foo() -> std::io::Result<()> {
/// ```rust,no_run
/// use std::fs;
///
/// let attr = fs::symlink_metadata("/some/file/path.txt")?;
/// // inspect attr ...
/// # Ok(())
/// # }
/// fn main() -> std::io::Result<()> {
/// let attr = fs::symlink_metadata("/some/file/path.txt")?;
/// // inspect attr ...
/// Ok(())
/// }
/// ```
#[stable(feature = "symlink_metadata", since = "1.1.0")]
pub fn symlink_metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> {
@ -1542,13 +1543,13 @@ pub fn symlink_metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
///
/// # fn foo() -> std::io::Result<()> {
/// fs::rename("a.txt", "b.txt")?; // Rename a.txt to b.txt
/// # Ok(())
/// # }
/// fn main() -> std::io::Result<()> {
/// fs::rename("a.txt", "b.txt")?; // Rename a.txt to b.txt
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<()> {
@ -1593,9 +1594,10 @@ pub fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<()>
/// ```no_run
/// use std::fs;
///
/// # fn foo() -> std::io::Result<()> {
/// fs::copy("foo.txt", "bar.txt")?; // Copy foo.txt to bar.txt
/// # Ok(()) }
/// fn main() -> std::io::Result<()> {
/// fs::copy("foo.txt", "bar.txt")?; // Copy foo.txt to bar.txt
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<u64> {
@ -1624,13 +1626,13 @@ pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<u64> {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
///
/// # fn foo() -> std::io::Result<()> {
/// fs::hard_link("a.txt", "b.txt")?; // Hard link a.txt to b.txt
/// # Ok(())
/// # }
/// fn main() -> std::io::Result<()> {
/// fs::hard_link("a.txt", "b.txt")?; // Hard link a.txt to b.txt
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn hard_link<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()> {
@ -1647,13 +1649,13 @@ pub fn hard_link<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<(
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
///
/// # fn foo() -> std::io::Result<()> {
/// fs::soft_link("a.txt", "b.txt")?;
/// # Ok(())
/// # }
/// fn main() -> std::io::Result<()> {
/// fs::soft_link("a.txt", "b.txt")?;
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_deprecated(since = "1.1.0",
@ -1684,13 +1686,13 @@ pub fn soft_link<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<(
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
///
/// # fn foo() -> std::io::Result<()> {
/// let path = fs::read_link("a.txt")?;
/// # Ok(())
/// # }
/// fn main() -> std::io::Result<()> {
/// let path = fs::read_link("a.txt")?;
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn read_link<P: AsRef<Path>>(path: P) -> io::Result<PathBuf> {
@ -1718,13 +1720,13 @@ pub fn read_link<P: AsRef<Path>>(path: P) -> io::Result<PathBuf> {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
///
/// # fn foo() -> std::io::Result<()> {
/// let path = fs::canonicalize("../a/../foo.txt")?;
/// # Ok(())
/// # }
/// fn main() -> std::io::Result<()> {
/// let path = fs::canonicalize("../a/../foo.txt")?;
/// Ok(())
/// }
/// ```
#[stable(feature = "fs_canonicalize", since = "1.5.0")]
pub fn canonicalize<P: AsRef<Path>>(path: P) -> io::Result<PathBuf> {
@ -1751,13 +1753,13 @@ pub fn canonicalize<P: AsRef<Path>>(path: P) -> io::Result<PathBuf> {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
///
/// # fn foo() -> std::io::Result<()> {
/// fs::create_dir("/some/dir")?;
/// # Ok(())
/// # }
/// fn main() -> std::io::Result<()> {
/// fs::create_dir("/some/dir")?;
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn create_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
@ -1793,13 +1795,13 @@ pub fn create_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
///
/// # fn foo() -> std::io::Result<()> {
/// fs::create_dir_all("/some/dir")?;
/// # Ok(())
/// # }
/// fn main() -> std::io::Result<()> {
/// fs::create_dir_all("/some/dir")?;
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn create_dir_all<P: AsRef<Path>>(path: P) -> io::Result<()> {
@ -1826,13 +1828,13 @@ pub fn create_dir_all<P: AsRef<Path>>(path: P) -> io::Result<()> {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
///
/// # fn foo() -> std::io::Result<()> {
/// fs::remove_dir("/some/dir")?;
/// # Ok(())
/// # }
/// fn main() -> std::io::Result<()> {
/// fs::remove_dir("/some/dir")?;
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn remove_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
@ -1860,13 +1862,13 @@ pub fn remove_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
///
/// # fn foo() -> std::io::Result<()> {
/// fs::remove_dir_all("/some/dir")?;
/// # Ok(())
/// # }
/// fn main() -> std::io::Result<()> {
/// fs::remove_dir_all("/some/dir")?;
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn remove_dir_all<P: AsRef<Path>>(path: P) -> io::Result<()> {
@ -1946,15 +1948,15 @@ pub fn read_dir<P: AsRef<Path>>(path: P) -> io::Result<ReadDir> {
///
/// # Examples
///
/// ```
/// # fn foo() -> std::io::Result<()> {
/// ```no_run
/// use std::fs;
///
/// let mut perms = fs::metadata("foo.txt")?.permissions();
/// perms.set_readonly(true);
/// fs::set_permissions("foo.txt", perms)?;
/// # Ok(())
/// # }
/// fn main() -> std::io::Result<()> {
/// let mut perms = fs::metadata("foo.txt")?.permissions();
/// perms.set_readonly(true);
/// fs::set_permissions("foo.txt", perms)?;
/// Ok(())
/// }
/// ```
#[stable(feature = "set_permissions", since = "1.1.0")]
pub fn set_permissions<P: AsRef<Path>>(path: P, perm: Permissions)

View File

@ -31,20 +31,20 @@ use memchr;
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::io::prelude::*;
/// use std::io::BufReader;
/// use std::fs::File;
///
/// # fn foo() -> std::io::Result<()> {
/// let f = File::open("log.txt")?;
/// let mut reader = BufReader::new(f);
/// fn main() -> std::io::Result<()> {
/// let f = File::open("log.txt")?;
/// let mut reader = BufReader::new(f);
///
/// let mut line = String::new();
/// let len = reader.read_line(&mut line)?;
/// println!("First line is {} bytes long", len);
/// # Ok(())
/// # }
/// let mut line = String::new();
/// let len = reader.read_line(&mut line)?;
/// println!("First line is {} bytes long", len);
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub struct BufReader<R> {
@ -59,15 +59,15 @@ impl<R: Read> BufReader<R> {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::io::BufReader;
/// use std::fs::File;
///
/// # fn foo() -> std::io::Result<()> {
/// let f = File::open("log.txt")?;
/// let reader = BufReader::new(f);
/// # Ok(())
/// # }
/// fn main() -> std::io::Result<()> {
/// let f = File::open("log.txt")?;
/// let reader = BufReader::new(f);
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new(inner: R) -> BufReader<R> {
@ -80,15 +80,15 @@ impl<R: Read> BufReader<R> {
///
/// Creating a buffer with ten bytes of capacity:
///
/// ```
/// ```no_run
/// use std::io::BufReader;
/// use std::fs::File;
///
/// # fn foo() -> std::io::Result<()> {
/// let f = File::open("log.txt")?;
/// let reader = BufReader::with_capacity(10, f);
/// # Ok(())
/// # }
/// fn main() -> std::io::Result<()> {
/// let f = File::open("log.txt")?;
/// let reader = BufReader::with_capacity(10, f);
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn with_capacity(cap: usize, inner: R) -> BufReader<R> {
@ -111,17 +111,17 @@ impl<R: Read> BufReader<R> {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::io::BufReader;
/// use std::fs::File;
///
/// # fn foo() -> std::io::Result<()> {
/// let f1 = File::open("log.txt")?;
/// let reader = BufReader::new(f1);
/// fn main() -> std::io::Result<()> {
/// let f1 = File::open("log.txt")?;
/// let reader = BufReader::new(f1);
///
/// let f2 = reader.get_ref();
/// # Ok(())
/// # }
/// let f2 = reader.get_ref();
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn get_ref(&self) -> &R { &self.inner }
@ -132,17 +132,17 @@ impl<R: Read> BufReader<R> {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::io::BufReader;
/// use std::fs::File;
///
/// # fn foo() -> std::io::Result<()> {
/// let f1 = File::open("log.txt")?;
/// let mut reader = BufReader::new(f1);
/// fn main() -> std::io::Result<()> {
/// let f1 = File::open("log.txt")?;
/// let mut reader = BufReader::new(f1);
///
/// let f2 = reader.get_mut();
/// # Ok(())
/// # }
/// let f2 = reader.get_mut();
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn get_mut(&mut self) -> &mut R { &mut self.inner }
@ -150,22 +150,23 @@ impl<R: Read> BufReader<R> {
/// Returns `true` if there are no bytes in the internal buffer.
///
/// # Examples
/// ```
//
/// ```no_run
/// # #![feature(bufreader_is_empty)]
/// use std::io::BufReader;
/// use std::io::BufRead;
/// use std::fs::File;
///
/// # fn foo() -> std::io::Result<()> {
/// let f1 = File::open("log.txt")?;
/// let mut reader = BufReader::new(f1);
/// assert!(reader.is_empty());
/// fn main() -> std::io::Result<()> {
/// let f1 = File::open("log.txt")?;
/// let mut reader = BufReader::new(f1);
/// assert!(reader.is_empty());
///
/// if reader.fill_buf()?.len() > 0 {
/// assert!(!reader.is_empty());
/// if reader.fill_buf()?.len() > 0 {
/// assert!(!reader.is_empty());
/// }
/// Ok(())
/// }
/// # Ok(())
/// # }
/// ```
#[unstable(feature = "bufreader_is_empty", issue = "45323", reason = "recently added")]
#[rustc_deprecated(since = "1.26.0", reason = "use .buffer().is_empty() instead")]
@ -179,21 +180,21 @@ impl<R: Read> BufReader<R> {
///
/// # Examples
///
/// ```
/// ```no_ru
/// # #![feature(bufreader_buffer)]
/// use std::io::{BufReader, BufRead};
/// use std::fs::File;
///
/// # fn foo() -> std::io::Result<()> {
/// let f = File::open("log.txt")?;
/// let mut reader = BufReader::new(f);
/// assert!(reader.buffer().is_empty());
/// fn main() -> std::io::Result<()> {
/// let f = File::open("log.txt")?;
/// let mut reader = BufReader::new(f);
/// assert!(reader.buffer().is_empty());
///
/// if reader.fill_buf()?.len() > 0 {
/// assert!(!reader.buffer().is_empty());
/// if reader.fill_buf()?.len() > 0 {
/// assert!(!reader.buffer().is_empty());
/// }
/// Ok(())
/// }
/// # Ok(())
/// # }
/// ```
#[unstable(feature = "bufreader_buffer", issue = "45323")]
pub fn buffer(&self) -> &[u8] {
@ -206,17 +207,17 @@ impl<R: Read> BufReader<R> {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::io::BufReader;
/// use std::fs::File;
///
/// # fn foo() -> std::io::Result<()> {
/// let f1 = File::open("log.txt")?;
/// let reader = BufReader::new(f1);
/// fn main() -> std::io::Result<()> {
/// let f1 = File::open("log.txt")?;
/// let reader = BufReader::new(f1);
///
/// let f2 = reader.into_inner();
/// # Ok(())
/// # }
/// let f2 = reader.into_inner();
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn into_inner(self) -> R { self.inner }
@ -724,34 +725,34 @@ impl<W> fmt::Display for IntoInnerError<W> {
/// We can use `LineWriter` to write one line at a time, significantly
/// reducing the number of actual writes to the file.
///
/// ```
/// ```no_run
/// use std::fs::File;
/// use std::io::prelude::*;
/// use std::io::LineWriter;
///
/// # fn foo() -> std::io::Result<()> {
/// let road_not_taken = b"I shall be telling this with a sigh
/// fn main() -> std::io::Result<()> {
/// let road_not_taken = b"I shall be telling this with a sigh
/// Somewhere ages and ages hence:
/// Two roads diverged in a wood, and I -
/// I took the one less traveled by,
/// And that has made all the difference.";
///
/// let file = File::create("poem.txt")?;
/// let mut file = LineWriter::new(file);
/// let file = File::create("poem.txt")?;
/// let mut file = LineWriter::new(file);
///
/// for &byte in road_not_taken.iter() {
/// file.write(&[byte]).unwrap();
/// for &byte in road_not_taken.iter() {
/// file.write(&[byte]).unwrap();
/// }
///
/// // let's check we did the right thing.
/// let mut file = File::open("poem.txt")?;
/// let mut contents = String::new();
///
/// file.read_to_string(&mut contents)?;
///
/// assert_eq!(contents.as_bytes(), &road_not_taken[..]);
/// Ok(())
/// }
///
/// // let's check we did the right thing.
/// let mut file = File::open("poem.txt")?;
/// let mut contents = String::new();
///
/// file.read_to_string(&mut contents)?;
///
/// assert_eq!(contents.as_bytes(), &road_not_taken[..]);
/// # Ok(())
/// # }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub struct LineWriter<W: Write> {
@ -764,15 +765,15 @@ impl<W: Write> LineWriter<W> {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs::File;
/// use std::io::LineWriter;
///
/// # fn foo() -> std::io::Result<()> {
/// let file = File::create("poem.txt")?;
/// let file = LineWriter::new(file);
/// # Ok(())
/// # }
/// fn main() -> std::io::Result<()> {
/// let file = File::create("poem.txt")?;
/// let file = LineWriter::new(file);
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new(inner: W) -> LineWriter<W> {
@ -785,15 +786,15 @@ impl<W: Write> LineWriter<W> {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs::File;
/// use std::io::LineWriter;
///
/// # fn foo() -> std::io::Result<()> {
/// let file = File::create("poem.txt")?;
/// let file = LineWriter::with_capacity(100, file);
/// # Ok(())
/// # }
/// fn main() -> std::io::Result<()> {
/// let file = File::create("poem.txt")?;
/// let file = LineWriter::with_capacity(100, file);
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn with_capacity(cap: usize, inner: W) -> LineWriter<W> {
@ -807,17 +808,17 @@ impl<W: Write> LineWriter<W> {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs::File;
/// use std::io::LineWriter;
///
/// # fn foo() -> std::io::Result<()> {
/// let file = File::create("poem.txt")?;
/// let file = LineWriter::new(file);
/// fn main() -> std::io::Result<()> {
/// let file = File::create("poem.txt")?;
/// let file = LineWriter::new(file);
///
/// let reference = file.get_ref();
/// # Ok(())
/// # }
/// let reference = file.get_ref();
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn get_ref(&self) -> &W { self.inner.get_ref() }
@ -829,18 +830,18 @@ impl<W: Write> LineWriter<W> {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs::File;
/// use std::io::LineWriter;
///
/// # fn foo() -> std::io::Result<()> {
/// let file = File::create("poem.txt")?;
/// let mut file = LineWriter::new(file);
/// fn main() -> std::io::Result<()> {
/// let file = File::create("poem.txt")?;
/// let mut file = LineWriter::new(file);
///
/// // we can use reference just like file
/// let reference = file.get_mut();
/// # Ok(())
/// # }
/// // we can use reference just like file
/// let reference = file.get_mut();
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() }
@ -855,18 +856,18 @@ impl<W: Write> LineWriter<W> {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs::File;
/// use std::io::LineWriter;
///
/// # fn foo() -> std::io::Result<()> {
/// let file = File::create("poem.txt")?;
/// fn main() -> std::io::Result<()> {
/// let file = File::create("poem.txt")?;
///
/// let writer: LineWriter<File> = LineWriter::new(file);
/// let writer: LineWriter<File> = LineWriter::new(file);
///
/// let file: File = writer.into_inner()?;
/// # Ok(())
/// # }
/// let file: File = writer.into_inner()?;
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn into_inner(self) -> Result<W, IntoInnerError<LineWriter<W>>> {

File diff suppressed because it is too large Load Diff

View File

@ -171,29 +171,29 @@ pub struct StdinLock<'a> {
///
/// Using implicit synchronization:
///
/// ```
/// ```no_run
/// use std::io::{self, Read};
///
/// # fn foo() -> io::Result<String> {
/// let mut buffer = String::new();
/// io::stdin().read_to_string(&mut buffer)?;
/// # Ok(buffer)
/// # }
/// fn main() -> io::Result<()> {
/// let mut buffer = String::new();
/// io::stdin().read_to_string(&mut buffer)?;
/// Ok(())
/// }
/// ```
///
/// Using explicit synchronization:
///
/// ```
/// ```no_run
/// use std::io::{self, Read};
///
/// # fn foo() -> io::Result<String> {
/// let mut buffer = String::new();
/// let stdin = io::stdin();
/// let mut handle = stdin.lock();
/// fn main() -> io::Result<()> {
/// let mut buffer = String::new();
/// let stdin = io::stdin();
/// let mut handle = stdin.lock();
///
/// handle.read_to_string(&mut buffer)?;
/// # Ok(buffer)
/// # }
/// handle.read_to_string(&mut buffer)?;
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn stdin() -> Stdin {
@ -225,17 +225,17 @@ impl Stdin {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::io::{self, Read};
///
/// # fn foo() -> io::Result<String> {
/// let mut buffer = String::new();
/// let stdin = io::stdin();
/// let mut handle = stdin.lock();
/// fn main() -> io::Result<()> {
/// let mut buffer = String::new();
/// let stdin = io::stdin();
/// let mut handle = stdin.lock();
///
/// handle.read_to_string(&mut buffer)?;
/// # Ok(buffer)
/// # }
/// handle.read_to_string(&mut buffer)?;
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn lock(&self) -> StdinLock {
@ -369,29 +369,29 @@ pub struct StdoutLock<'a> {
///
/// Using implicit synchronization:
///
/// ```
/// ```no_run
/// use std::io::{self, Write};
///
/// # fn foo() -> io::Result<()> {
/// io::stdout().write(b"hello world")?;
/// fn main() -> io::Result<()> {
/// io::stdout().write(b"hello world")?;
///
/// # Ok(())
/// # }
/// Ok(())
/// }
/// ```
///
/// Using explicit synchronization:
///
/// ```
/// ```no_run
/// use std::io::{self, Write};
///
/// # fn foo() -> io::Result<()> {
/// let stdout = io::stdout();
/// let mut handle = stdout.lock();
/// fn main() -> io::Result<()> {
/// let stdout = io::stdout();
/// let mut handle = stdout.lock();
///
/// handle.write(b"hello world")?;
/// handle.write(b"hello world")?;
///
/// # Ok(())
/// # }
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn stdout() -> Stdout {
@ -419,17 +419,17 @@ impl Stdout {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::io::{self, Write};
///
/// # fn foo() -> io::Result<()> {
/// let stdout = io::stdout();
/// let mut handle = stdout.lock();
/// fn main() -> io::Result<()> {
/// let stdout = io::stdout();
/// let mut handle = stdout.lock();
///
/// handle.write(b"hello world")?;
/// handle.write(b"hello world")?;
///
/// # Ok(())
/// # }
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn lock(&self) -> StdoutLock {
@ -505,29 +505,29 @@ pub struct StderrLock<'a> {
///
/// Using implicit synchronization:
///
/// ```
/// ```no_run
/// use std::io::{self, Write};
///
/// # fn foo() -> io::Result<()> {
/// io::stderr().write(b"hello world")?;
/// fn main() -> io::Result<()> {
/// io::stderr().write(b"hello world")?;
///
/// # Ok(())
/// # }
/// Ok(())
/// }
/// ```
///
/// Using explicit synchronization:
///
/// ```
/// ```no_run
/// use std::io::{self, Write};
///
/// # fn foo() -> io::Result<()> {
/// let stderr = io::stderr();
/// let mut handle = stderr.lock();
/// fn main() -> io::Result<()> {
/// let stderr = io::stderr();
/// let mut handle = stderr.lock();
///
/// handle.write(b"hello world")?;
/// handle.write(b"hello world")?;
///
/// # Ok(())
/// # }
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn stderr() -> Stderr {

View File

@ -34,16 +34,15 @@ use mem;
/// ```
/// use std::io;
///
/// # fn foo() -> io::Result<()> {
/// let mut reader: &[u8] = b"hello";
/// let mut writer: Vec<u8> = vec![];
/// fn main() -> io::Result<()> {
/// let mut reader: &[u8] = b"hello";
/// let mut writer: Vec<u8> = vec![];
///
/// io::copy(&mut reader, &mut writer)?;
/// io::copy(&mut reader, &mut writer)?;
///
/// assert_eq!(&b"hello"[..], &writer[..]);
/// # Ok(())
/// # }
/// # foo().unwrap();
/// assert_eq!(&b"hello"[..], &writer[..]);
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn copy<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W) -> io::Result<u64>

View File

@ -175,12 +175,12 @@ impl fmt::Debug for LookupHost {
///
/// use std::net;
///
/// # fn foo() -> std::io::Result<()> {
/// for host in net::lookup_host("rust-lang.org")? {
/// println!("found address: {}", host);
/// fn main() -> std::io::Result<()> {
/// for host in net::lookup_host("rust-lang.org")? {
/// println!("found address: {}", host);
/// }
/// Ok(())
/// }
/// # Ok(())
/// # }
/// ```
#[unstable(feature = "lookup_host", reason = "unsure about the returned \
iterator and returning socket \

View File

@ -72,7 +72,7 @@ pub struct TcpStream(net_imp::TcpStream);
///
/// # Examples
///
/// ```
/// ```no_run
/// # use std::io;
/// use std::net::{TcpListener, TcpStream};
///
@ -80,15 +80,15 @@ pub struct TcpStream(net_imp::TcpStream);
/// // ...
/// }
///
/// # fn process() -> io::Result<()> {
/// let listener = TcpListener::bind("127.0.0.1:80").unwrap();
/// fn main() -> io::Result<()> {
/// let listener = TcpListener::bind("127.0.0.1:80").unwrap();
///
/// // accept connections and process them serially
/// for stream in listener.incoming() {
/// handle_client(stream?);
/// // accept connections and process them serially
/// for stream in listener.incoming() {
/// handle_client(stream?);
/// }
/// Ok(())
/// }
/// # Ok(())
/// # }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub struct TcpListener(net_imp::TcpListener);

View File

@ -44,22 +44,22 @@ use time::Duration;
/// ```no_run
/// use std::net::UdpSocket;
///
/// # fn foo() -> std::io::Result<()> {
/// {
/// let mut socket = UdpSocket::bind("127.0.0.1:34254")?;
/// fn main() -> std::io::Result<()> {
/// {
/// let mut socket = UdpSocket::bind("127.0.0.1:34254")?;
///
/// // Receives a single datagram message on the socket. If `buf` is too small to hold
/// // the message, it will be cut off.
/// let mut buf = [0; 10];
/// let (amt, src) = socket.recv_from(&mut buf)?;
/// // Receives a single datagram message on the socket. If `buf` is too small to hold
/// // the message, it will be cut off.
/// let mut buf = [0; 10];
/// let (amt, src) = socket.recv_from(&mut buf)?;
///
/// // Redeclare `buf` as slice of the received data and send reverse data back to origin.
/// let buf = &mut buf[..amt];
/// buf.reverse();
/// socket.send_to(buf, &src)?;
/// # Ok(())
/// } // the socket is closed here
/// # }
/// // Redeclare `buf` as slice of the received data and send reverse data back to origin.
/// let buf = &mut buf[..amt];
/// buf.reverse();
/// socket.send_to(buf, &src)?;
/// } // the socket is closed here
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub struct UdpSocket(net_imp::UdpSocket);

View File

@ -32,16 +32,16 @@ pub trait MetadataExt {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let stat = meta.as_raw_stat();
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let stat = meta.as_raw_stat();
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext", since = "1.1.0")]
#[rustc_deprecated(since = "1.8.0",
@ -54,16 +54,16 @@ pub trait MetadataExt {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_dev());
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_dev());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_dev(&self) -> u64;
@ -71,16 +71,16 @@ pub trait MetadataExt {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_ino());
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_ino());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_ino(&self) -> u64;
@ -88,16 +88,16 @@ pub trait MetadataExt {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_mode());
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_mode());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_mode(&self) -> u32;
@ -105,16 +105,16 @@ pub trait MetadataExt {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_nlink());
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_nlink());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_nlink(&self) -> u64;
@ -122,16 +122,16 @@ pub trait MetadataExt {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_uid());
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_uid());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_uid(&self) -> u32;
@ -139,16 +139,16 @@ pub trait MetadataExt {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_gid());
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_gid());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_gid(&self) -> u32;
@ -156,16 +156,16 @@ pub trait MetadataExt {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_rdev());
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_rdev());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_rdev(&self) -> u64;
@ -176,16 +176,16 @@ pub trait MetadataExt {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_size());
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_size());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_size(&self) -> u64;
@ -193,16 +193,16 @@ pub trait MetadataExt {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_atime());
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_atime());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_atime(&self) -> i64;
@ -210,16 +210,16 @@ pub trait MetadataExt {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_atime_nsec());
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_atime_nsec());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_atime_nsec(&self) -> i64;
@ -227,16 +227,16 @@ pub trait MetadataExt {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_mtime());
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_mtime());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_mtime(&self) -> i64;
@ -244,16 +244,16 @@ pub trait MetadataExt {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_mtime_nsec());
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_mtime_nsec());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_mtime_nsec(&self) -> i64;
@ -261,16 +261,16 @@ pub trait MetadataExt {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_ctime());
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_ctime());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_ctime(&self) -> i64;
@ -278,16 +278,16 @@ pub trait MetadataExt {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_ctime_nsec());
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_ctime_nsec());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_ctime_nsec(&self) -> i64;
@ -295,16 +295,16 @@ pub trait MetadataExt {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_blksize());
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_blksize());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_blksize(&self) -> u64;
@ -312,16 +312,16 @@ pub trait MetadataExt {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_blocks());
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_blocks());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_blocks(&self) -> u64;

View File

@ -30,13 +30,14 @@ pub trait PermissionsExt {
/// use std::fs::File;
/// use std::os::redox::fs::PermissionsExt;
///
/// # fn run() -> std::io::Result<()> {
/// let f = File::create("foo.txt")?;
/// let metadata = f.metadata()?;
/// let permissions = metadata.permissions();
/// fn main() -> std::io::Result<()> {
/// let f = File::create("foo.txt")?;
/// let metadata = f.metadata()?;
/// let permissions = metadata.permissions();
///
/// println!("permissions: {}", permissions.mode());
/// # Ok(()) }
/// println!("permissions: {}", permissions.mode());
/// Ok(())
/// }
/// ```
#[stable(feature = "fs_ext", since = "1.1.0")]
fn mode(&self) -> u32;
@ -49,14 +50,15 @@ pub trait PermissionsExt {
/// use std::fs::File;
/// use std::os::redox::fs::PermissionsExt;
///
/// # fn run() -> std::io::Result<()> {
/// let f = File::create("foo.txt")?;
/// let metadata = f.metadata()?;
/// let mut permissions = metadata.permissions();
/// fn main() -> std::io::Result<()> {
/// let f = File::create("foo.txt")?;
/// let metadata = f.metadata()?;
/// let mut permissions = metadata.permissions();
///
/// permissions.set_mode(0o644); // Read/write for owner and read for others.
/// assert_eq!(permissions.mode(), 0o644);
/// # Ok(()) }
/// permissions.set_mode(0o644); // Read/write for owner and read for others.
/// assert_eq!(permissions.mode(), 0o644);
/// Ok(())
/// }
/// ```
#[stable(feature = "fs_ext", since = "1.1.0")]
fn set_mode(&mut self, mode: u32);
@ -291,13 +293,13 @@ impl FileTypeExt for fs::FileType {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::os::redox::fs;
///
/// # fn foo() -> std::io::Result<()> {
/// fs::symlink("a.txt", "b.txt")?;
/// # Ok(())
/// # }
/// fn main() -> std::io::Result<()> {
/// fs::symlink("a.txt", "b.txt")?;
/// Ok(())
/// }
/// ```
#[stable(feature = "symlink", since = "1.1.0")]
pub fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()>

View File

@ -41,20 +41,20 @@ pub trait FileExt {
///
/// # Examples
///
/// ```
/// use std::os::unix::prelude::FileExt;
/// ```no_run
/// use std::io;
/// use std::fs::File;
/// use std::os::unix::prelude::FileExt;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let mut buf = [0u8; 8];
/// let file = File::open("foo.txt")?;
/// fn main() -> io::Result<()> {
/// let mut buf = [0u8; 8];
/// let file = File::open("foo.txt")?;
///
/// // We now read 8 bytes from the offset 10.
/// let num_bytes_read = file.read_at(&mut buf, 10)?;
/// println!("read {} bytes: {:?}", num_bytes_read, buf);
/// # Ok(())
/// # }
/// // We now read 8 bytes from the offset 10.
/// let num_bytes_read = file.read_at(&mut buf, 10)?;
/// println!("read {} bytes: {:?}", num_bytes_read, buf);
/// Ok(())
/// }
/// ```
#[stable(feature = "file_offset", since = "1.15.0")]
fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result<usize>;
@ -78,18 +78,18 @@ pub trait FileExt {
///
/// # Examples
///
/// ```
/// use std::os::unix::prelude::FileExt;
/// ```no_run
/// use std::fs::File;
/// use std::io;
/// use std::os::unix::prelude::FileExt;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let file = File::open("foo.txt")?;
/// fn main() -> io::Result<()> {
/// let file = File::open("foo.txt")?;
///
/// // We now write at the offset 10.
/// file.write_at(b"sushi", 10)?;
/// # Ok(())
/// # }
/// // We now write at the offset 10.
/// file.write_at(b"sushi", 10)?;
/// Ok(())
/// }
/// ```
#[stable(feature = "file_offset", since = "1.15.0")]
fn write_at(&self, buf: &[u8], offset: u64) -> io::Result<usize>;
@ -117,13 +117,13 @@ pub trait PermissionsExt {
/// use std::fs::File;
/// use std::os::unix::fs::PermissionsExt;
///
/// # fn run() -> std::io::Result<()> {
/// let f = File::create("foo.txt")?;
/// let metadata = f.metadata()?;
/// let permissions = metadata.permissions();
/// fn main() -> std::io::Result<()> {
/// let f = File::create("foo.txt")?;
/// let metadata = f.metadata()?;
/// let permissions = metadata.permissions();
///
/// println!("permissions: {}", permissions.mode());
/// # Ok(()) }
/// println!("permissions: {}", permissions.mode());
/// Ok(()) }
/// ```
#[stable(feature = "fs_ext", since = "1.1.0")]
fn mode(&self) -> u32;
@ -136,14 +136,14 @@ pub trait PermissionsExt {
/// use std::fs::File;
/// use std::os::unix::fs::PermissionsExt;
///
/// # fn run() -> std::io::Result<()> {
/// let f = File::create("foo.txt")?;
/// let metadata = f.metadata()?;
/// let mut permissions = metadata.permissions();
/// fn main() -> std::io::Result<()> {
/// let f = File::create("foo.txt")?;
/// let metadata = f.metadata()?;
/// let mut permissions = metadata.permissions();
///
/// permissions.set_mode(0o644); // Read/write for owner and read for others.
/// assert_eq!(permissions.mode(), 0o644);
/// # Ok(()) }
/// permissions.set_mode(0o644); // Read/write for owner and read for others.
/// assert_eq!(permissions.mode(), 0o644);
/// Ok(()) }
/// ```
#[stable(feature = "fs_ext", since = "1.1.0")]
fn set_mode(&mut self, mode: u32);
@ -260,15 +260,15 @@ pub trait MetadataExt {
/// # Examples
///
/// ```no_run
/// use std::io;
/// use std::fs;
/// use std::os::unix::fs::MetadataExt;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let dev_id = meta.dev();
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let dev_id = meta.dev();
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn dev(&self) -> u64;
@ -279,13 +279,13 @@ pub trait MetadataExt {
/// ```no_run
/// use std::fs;
/// use std::os::unix::fs::MetadataExt;
/// use std::io;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let inode = meta.ino();
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let inode = meta.ino();
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn ino(&self) -> u64;
@ -296,17 +296,17 @@ pub trait MetadataExt {
/// ```no_run
/// use std::fs;
/// use std::os::unix::fs::MetadataExt;
/// use std::io;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let mode = meta.mode();
/// let user_has_write_access = mode & 0o200;
/// let user_has_read_write_access = mode & 0o600;
/// let group_has_read_access = mode & 0o040;
/// let others_have_exec_access = mode & 0o001;
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let mode = meta.mode();
/// let user_has_write_access = mode & 0o200;
/// let user_has_read_write_access = mode & 0o600;
/// let group_has_read_access = mode & 0o040;
/// let others_have_exec_access = mode & 0o001;
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn mode(&self) -> u32;
@ -317,13 +317,13 @@ pub trait MetadataExt {
/// ```no_run
/// use std::fs;
/// use std::os::unix::fs::MetadataExt;
/// use std::io;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let nb_hard_links = meta.nlink();
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let nb_hard_links = meta.nlink();
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn nlink(&self) -> u64;
@ -334,13 +334,13 @@ pub trait MetadataExt {
/// ```no_run
/// use std::fs;
/// use std::os::unix::fs::MetadataExt;
/// use std::io;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let user_id = meta.uid();
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let user_id = meta.uid();
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn uid(&self) -> u32;
@ -351,13 +351,13 @@ pub trait MetadataExt {
/// ```no_run
/// use std::fs;
/// use std::os::unix::fs::MetadataExt;
/// use std::io;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let group_id = meta.gid();
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let group_id = meta.gid();
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn gid(&self) -> u32;
@ -368,13 +368,13 @@ pub trait MetadataExt {
/// ```no_run
/// use std::fs;
/// use std::os::unix::fs::MetadataExt;
/// use std::io;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let device_id = meta.rdev();
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let device_id = meta.rdev();
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn rdev(&self) -> u64;
@ -385,13 +385,13 @@ pub trait MetadataExt {
/// ```no_run
/// use std::fs;
/// use std::os::unix::fs::MetadataExt;
/// use std::io;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let file_size = meta.size();
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let file_size = meta.size();
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn size(&self) -> u64;
@ -402,13 +402,13 @@ pub trait MetadataExt {
/// ```no_run
/// use std::fs;
/// use std::os::unix::fs::MetadataExt;
/// use std::io;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let last_access_time = meta.atime();
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let last_access_time = meta.atime();
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn atime(&self) -> i64;
@ -419,13 +419,13 @@ pub trait MetadataExt {
/// ```no_run
/// use std::fs;
/// use std::os::unix::fs::MetadataExt;
/// use std::io;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let nano_last_access_time = meta.atime_nsec();
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let nano_last_access_time = meta.atime_nsec();
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn atime_nsec(&self) -> i64;
@ -436,13 +436,13 @@ pub trait MetadataExt {
/// ```no_run
/// use std::fs;
/// use std::os::unix::fs::MetadataExt;
/// use std::io;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let last_modification_time = meta.mtime();
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let last_modification_time = meta.mtime();
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn mtime(&self) -> i64;
@ -453,13 +453,13 @@ pub trait MetadataExt {
/// ```no_run
/// use std::fs;
/// use std::os::unix::fs::MetadataExt;
/// use std::io;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let nano_last_modification_time = meta.mtime_nsec();
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let nano_last_modification_time = meta.mtime_nsec();
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn mtime_nsec(&self) -> i64;
@ -470,13 +470,13 @@ pub trait MetadataExt {
/// ```no_run
/// use std::fs;
/// use std::os::unix::fs::MetadataExt;
/// use std::io;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let last_status_change_time = meta.ctime();
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let last_status_change_time = meta.ctime();
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn ctime(&self) -> i64;
@ -487,13 +487,13 @@ pub trait MetadataExt {
/// ```no_run
/// use std::fs;
/// use std::os::unix::fs::MetadataExt;
/// use std::io;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let nano_last_status_change_time = meta.ctime_nsec();
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let nano_last_status_change_time = meta.ctime_nsec();
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn ctime_nsec(&self) -> i64;
@ -504,13 +504,13 @@ pub trait MetadataExt {
/// ```no_run
/// use std::fs;
/// use std::os::unix::fs::MetadataExt;
/// use std::io;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let blocksize = meta.blksize();
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let blocksize = meta.blksize();
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn blksize(&self) -> u64;
@ -523,13 +523,13 @@ pub trait MetadataExt {
/// ```no_run
/// use std::fs;
/// use std::os::unix::fs::MetadataExt;
/// use std::io;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let blocks = meta.blocks();
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let blocks = meta.blocks();
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn blocks(&self) -> u64;
@ -562,17 +562,17 @@ pub trait FileTypeExt {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
/// use std::os::unix::fs::FileTypeExt;
/// use std::io;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("block_device_file")?;
/// let file_type = meta.file_type();
/// assert!(file_type.is_block_device());
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("block_device_file")?;
/// let file_type = meta.file_type();
/// assert!(file_type.is_block_device());
/// Ok(())
/// }
/// ```
#[stable(feature = "file_type_ext", since = "1.5.0")]
fn is_block_device(&self) -> bool;
@ -580,17 +580,17 @@ pub trait FileTypeExt {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
/// use std::os::unix::fs::FileTypeExt;
/// use std::io;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("char_device_file")?;
/// let file_type = meta.file_type();
/// assert!(file_type.is_char_device());
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("char_device_file")?;
/// let file_type = meta.file_type();
/// assert!(file_type.is_char_device());
/// Ok(())
/// }
/// ```
#[stable(feature = "file_type_ext", since = "1.5.0")]
fn is_char_device(&self) -> bool;
@ -598,17 +598,17 @@ pub trait FileTypeExt {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
/// use std::os::unix::fs::FileTypeExt;
/// use std::io;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("fifo_file")?;
/// let file_type = meta.file_type();
/// assert!(file_type.is_fifo());
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("fifo_file")?;
/// let file_type = meta.file_type();
/// assert!(file_type.is_fifo());
/// Ok(())
/// }
/// ```
#[stable(feature = "file_type_ext", since = "1.5.0")]
fn is_fifo(&self) -> bool;
@ -616,17 +616,17 @@ pub trait FileTypeExt {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::fs;
/// use std::os::unix::fs::FileTypeExt;
/// use std::io;
///
/// # use std::io;
/// # fn f() -> io::Result<()> {
/// let meta = fs::metadata("unix.socket")?;
/// let file_type = meta.file_type();
/// assert!(file_type.is_socket());
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("unix.socket")?;
/// let file_type = meta.file_type();
/// assert!(file_type.is_socket());
/// Ok(())
/// }
/// ```
#[stable(feature = "file_type_ext", since = "1.5.0")]
fn is_socket(&self) -> bool;
@ -687,13 +687,13 @@ impl DirEntryExt for fs::DirEntry {
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::os::unix::fs;
///
/// # fn foo() -> std::io::Result<()> {
/// fs::symlink("a.txt", "b.txt")?;
/// # Ok(())
/// # }
/// fn main() -> std::io::Result<()> {
/// fs::symlink("a.txt", "b.txt")?;
/// Ok(())
/// }
/// ```
#[stable(feature = "symlink", since = "1.1.0")]
pub fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()>

View File

@ -45,15 +45,15 @@ pub trait FileExt {
/// use std::fs::File;
/// use std::os::windows::prelude::*;
///
/// # fn foo() -> io::Result<()> {
/// let mut file = File::open("foo.txt")?;
/// let mut buffer = [0; 10];
/// fn main() -> io::Result<()> {
/// let mut file = File::open("foo.txt")?;
/// let mut buffer = [0; 10];
///
/// // Read 10 bytes, starting 72 bytes from the
/// // start of the file.
/// file.seek_read(&mut buffer[..], 72)?;
/// # Ok(())
/// # }
/// // Read 10 bytes, starting 72 bytes from the
/// // start of the file.
/// file.seek_read(&mut buffer[..], 72)?;
/// Ok(())
/// }
/// ```
#[stable(feature = "file_offset", since = "1.15.0")]
fn seek_read(&self, buf: &mut [u8], offset: u64) -> io::Result<usize>;
@ -79,14 +79,14 @@ pub trait FileExt {
/// use std::fs::File;
/// use std::os::windows::prelude::*;
///
/// # fn foo() -> std::io::Result<()> {
/// let mut buffer = File::create("foo.txt")?;
/// fn main() -> std::io::Result<()> {
/// let mut buffer = File::create("foo.txt")?;
///
/// // Write a byte string starting 72 bytes from
/// // the start of the file.
/// buffer.seek_write(b"some bytes", 72)?;
/// # Ok(())
/// # }
/// // Write a byte string starting 72 bytes from
/// // the start of the file.
/// buffer.seek_write(b"some bytes", 72)?;
/// Ok(())
/// }
/// ```
#[stable(feature = "file_offset", since = "1.15.0")]
fn seek_write(&self, buf: &[u8], offset: u64) -> io::Result<usize>;
@ -305,11 +305,11 @@ pub trait MetadataExt {
/// use std::fs;
/// use std::os::windows::prelude::*;
///
/// # fn foo() -> io::Result<()> {
/// let metadata = fs::metadata("foo.txt")?;
/// let attributes = metadata.file_attributes();
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let metadata = fs::metadata("foo.txt")?;
/// let attributes = metadata.file_attributes();
/// Ok(())
/// }
/// ```
///
/// [File Attribute Constants]:
@ -335,11 +335,11 @@ pub trait MetadataExt {
/// use std::fs;
/// use std::os::windows::prelude::*;
///
/// # fn foo() -> io::Result<()> {
/// let metadata = fs::metadata("foo.txt")?;
/// let creation_time = metadata.creation_time();
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let metadata = fs::metadata("foo.txt")?;
/// let creation_time = metadata.creation_time();
/// Ok(())
/// }
/// ```
///
/// [`FILETIME`]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724284.aspx
@ -370,11 +370,11 @@ pub trait MetadataExt {
/// use std::fs;
/// use std::os::windows::prelude::*;
///
/// # fn foo() -> io::Result<()> {
/// let metadata = fs::metadata("foo.txt")?;
/// let last_access_time = metadata.last_access_time();
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let metadata = fs::metadata("foo.txt")?;
/// let last_access_time = metadata.last_access_time();
/// Ok(())
/// }
/// ```
///
/// [`FILETIME`]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724284.aspx
@ -403,11 +403,11 @@ pub trait MetadataExt {
/// use std::fs;
/// use std::os::windows::prelude::*;
///
/// # fn foo() -> io::Result<()> {
/// let metadata = fs::metadata("foo.txt")?;
/// let last_write_time = metadata.last_write_time();
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let metadata = fs::metadata("foo.txt")?;
/// let last_write_time = metadata.last_write_time();
/// Ok(())
/// }
/// ```
///
/// [`FILETIME`]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724284.aspx
@ -426,11 +426,11 @@ pub trait MetadataExt {
/// use std::fs;
/// use std::os::windows::prelude::*;
///
/// # fn foo() -> io::Result<()> {
/// let metadata = fs::metadata("foo.txt")?;
/// let file_size = metadata.file_size();
/// # Ok(())
/// # }
/// fn main() -> io::Result<()> {
/// let metadata = fs::metadata("foo.txt")?;
/// let file_size = metadata.file_size();
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn file_size(&self) -> u64;
@ -473,10 +473,10 @@ impl FileTypeExt for fs::FileType {
/// ```no_run
/// use std::os::windows::fs;
///
/// # fn foo() -> std::io::Result<()> {
/// fs::symlink_file("a.txt", "b.txt")?;
/// # Ok(())
/// # }
/// fn main() -> std::io::Result<()> {
/// fs::symlink_file("a.txt", "b.txt")?;
/// Ok(())
/// }
/// ```
#[stable(feature = "symlink", since = "1.1.0")]
pub fn symlink_file<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q)
@ -494,10 +494,10 @@ pub fn symlink_file<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q)
/// ```no_run
/// use std::os::windows::fs;
///
/// # fn foo() -> std::io::Result<()> {
/// fs::symlink_dir("a", "b")?;
/// # Ok(())
/// # }
/// fn main() -> std::io::Result<()> {
/// fs::symlink_dir("a", "b")?;
/// Ok(())
/// }
/// ```
#[stable(feature = "symlink", since = "1.1.0")]
pub fn symlink_dir<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q)