diff options
| author | Jacob Pratt <jacob@jhpratt.dev> | 2025-02-11 01:02:40 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-11 01:02:40 -0500 |
| commit | 2996cfdcc3b9c46853f4a424079af1da6ce0e638 (patch) | |
| tree | f158d3a5a315f0e2b478dc21bfd0409fd390095e /library/std/src | |
| parent | aaf2c46202779a03ff1246acd8908ef5ccab0d15 (diff) | |
| parent | 8ea20c82bbb5ac7040fe8dab326849a47f851c97 (diff) | |
Rollup merge of #136704 - benschulz:patch-1, r=ibraheemdev
Improve examples for file locking The `lock` and `try_lock` documentation states that "if the file not open for writing, it is unspecified whether this function returns an error." With this change, the examples use `File::create` instead of `File::open`, eliminating the possibility of someone blindly copying code with unspecified behavior.
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/fs.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index 0871a9e22d3..83b009c86dc 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -664,7 +664,7 @@ impl File { /// use std::fs::File; /// /// fn main() -> std::io::Result<()> { - /// let f = File::open("foo.txt")?; + /// let f = File::create("foo.txt")?; /// f.lock()?; /// Ok(()) /// } @@ -767,7 +767,7 @@ impl File { /// use std::fs::File; /// /// fn main() -> std::io::Result<()> { - /// let f = File::open("foo.txt")?; + /// let f = File::create("foo.txt")?; /// f.try_lock()?; /// Ok(()) /// } |
