Demonstrate I/O in File examples

This commit is contained in:
Kornel 2023-02-15 18:47:50 +00:00
parent 999ac5f777
commit 15adc7b5e4

View file

@ -343,9 +343,12 @@ impl File {
///
/// ```no_run
/// use std::fs::File;
/// use std::io::Read;
///
/// fn main() -> std::io::Result<()> {
/// let mut f = File::open("foo.txt")?;
/// let mut data = vec![];
/// f.read_to_end(&mut data)?;
/// Ok(())
/// }
/// ```
@ -368,9 +371,11 @@ pub fn open<P: AsRef<Path>>(path: P) -> io::Result<File> {
///
/// ```no_run
/// use std::fs::File;
/// use std::io::Write;
///
/// fn main() -> std::io::Result<()> {
/// let mut f = File::create("foo.txt")?;
/// f.write_all(&1234_u32.to_be_bytes())?;
/// Ok(())
/// }
/// ```
@ -397,9 +402,11 @@ pub fn create<P: AsRef<Path>>(path: P) -> io::Result<File> {
/// #![feature(file_create_new)]
///
/// use std::fs::File;
/// use std::io::Write;
///
/// fn main() -> std::io::Result<()> {
/// let mut f = File::create_new("foo.txt")?;
/// f.write_all("Hello, world!".as_bytes())?;
/// Ok(())
/// }
/// ```
@ -426,9 +433,11 @@ pub fn create_new<P: AsRef<Path>>(path: P) -> io::Result<File> {
///
/// ```no_run
/// use std::fs::File;
/// use std::io::Write;
///
/// fn main() -> std::io::Result<()> {
/// let mut f = File::options().append(true).open("example.log")?;
/// writeln!(&mut f, "new line")?;
/// Ok(())
/// }
/// ```