about summary refs log tree commit diff
diff options
context:
space:
mode:
authorjethrogb <github@jbeekman.nl>2015-07-11 11:05:47 -0700
committerJethro Beekman <jethro@jbeekman.nl>2015-07-11 14:17:45 -0700
commit9262d647bb886fb6d1a846e33af2e95b35105459 (patch)
treef469a5db7f1a2c2398fbb1e16256ac8259872531
parent1b28ffa5216c845d1cef6b0cb3e5ac7db12025d0 (diff)
downloadrust-9262d647bb886fb6d1a846e33af2e95b35105459.tar.gz
rust-9262d647bb886fb6d1a846e33af2e95b35105459.zip
Change std::fs::File.set_len example and documentation
The File object needs to be writable for the truncate to succeed.
-rw-r--r--src/libstd/fs.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs
index 2458838bc9d..7598a1c7a48 100644
--- a/src/libstd/fs.rs
+++ b/src/libstd/fs.rs
@@ -269,14 +269,18 @@ impl File {
     /// will be extended to `size` and have all of the intermediate data filled
     /// in with 0s.
     ///
+    /// # Errors
+    ///
+    /// This function will return an error if the file is not opened for writing.
+    ///
     /// # Examples
     ///
     /// ```no_run
     /// use std::fs::File;
     ///
     /// # fn foo() -> std::io::Result<()> {
-    /// let mut f = try!(File::open("foo.txt"));
-    /// try!(f.set_len(0));
+    /// let mut f = try!(File::create("foo.txt"));
+    /// try!(f.set_len(10));
     /// # Ok(())
     /// # }
     /// ```