diff options
| author | Kornel <kornel@geekhood.net> | 2023-02-15 18:47:50 +0000 |
|---|---|---|
| committer | Kornel <kornel@geekhood.net> | 2023-02-15 18:47:50 +0000 |
| commit | 15adc7b5e430bdef0c6ba1526b510878ac0c69eb (patch) | |
| tree | 7640cc604493b087c49ab6ea0db5d480dc2cfe3d | |
| parent | 999ac5f7770bff68bd65f490990d32c3ec1faaa6 (diff) | |
| download | rust-15adc7b5e430bdef0c6ba1526b510878ac0c69eb.tar.gz rust-15adc7b5e430bdef0c6ba1526b510878ac0c69eb.zip | |
Demonstrate I/O in File examples
| -rw-r--r-- | library/std/src/fs.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index 286ad68fd13..8a2799b17b9 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -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 @@ impl 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 @@ impl 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 @@ impl 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(()) /// } /// ``` |
