Skip to content

Commit 15adc7b

Browse files
committed
Demonstrate I/O in File examples
1 parent 999ac5f commit 15adc7b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

library/std/src/fs.rs

+9
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,12 @@ impl File {
343343
///
344344
/// ```no_run
345345
/// use std::fs::File;
346+
/// use std::io::Read;
346347
///
347348
/// fn main() -> std::io::Result<()> {
348349
/// let mut f = File::open("foo.txt")?;
350+
/// let mut data = vec![];
351+
/// f.read_to_end(&mut data)?;
349352
/// Ok(())
350353
/// }
351354
/// ```
@@ -368,9 +371,11 @@ impl File {
368371
///
369372
/// ```no_run
370373
/// use std::fs::File;
374+
/// use std::io::Write;
371375
///
372376
/// fn main() -> std::io::Result<()> {
373377
/// let mut f = File::create("foo.txt")?;
378+
/// f.write_all(&1234_u32.to_be_bytes())?;
374379
/// Ok(())
375380
/// }
376381
/// ```
@@ -397,9 +402,11 @@ impl File {
397402
/// #![feature(file_create_new)]
398403
///
399404
/// use std::fs::File;
405+
/// use std::io::Write;
400406
///
401407
/// fn main() -> std::io::Result<()> {
402408
/// let mut f = File::create_new("foo.txt")?;
409+
/// f.write_all("Hello, world!".as_bytes())?;
403410
/// Ok(())
404411
/// }
405412
/// ```
@@ -426,9 +433,11 @@ impl File {
426433
///
427434
/// ```no_run
428435
/// use std::fs::File;
436+
/// use std::io::Write;
429437
///
430438
/// fn main() -> std::io::Result<()> {
431439
/// let mut f = File::options().append(true).open("example.log")?;
440+
/// writeln!(&mut f, "new line")?;
432441
/// Ok(())
433442
/// }
434443
/// ```

0 commit comments

Comments
 (0)