@@ -34,8 +34,28 @@ pub trait FileExt {
34
34
///
35
35
/// The current file cursor is not affected by this function.
36
36
///
37
- /// Note that similar to `File::read`, it is not an error to return with a
37
+ /// Note that similar to [ `File::read`] , it is not an error to return with a
38
38
/// short read.
39
+ ///
40
+ /// [`File::read`]: ../../../../std/fs/struct.File.html#method.read
41
+ ///
42
+ /// # Examples
43
+ ///
44
+ /// ```
45
+ /// use std::os::unix::prelude::FileExt;
46
+ /// use std::fs::File;
47
+ ///
48
+ /// # use std::io;
49
+ /// # fn f() -> io::Result<()> {
50
+ /// let mut buf = [0u8; 8];
51
+ /// let file = File::open("foo.txt")?;
52
+ ///
53
+ /// // We now read 8 bytes from the offset 10.
54
+ /// let num_bytes_read = file.read_at(&mut buf, 10)?;
55
+ /// println!("read {} bytes: {:?}", num_bytes_read, buf);
56
+ /// # Ok(())
57
+ /// # }
58
+ /// ```
39
59
#[ stable( feature = "file_offset" , since = "1.15.0" ) ]
40
60
fn read_at ( & self , buf : & mut [ u8 ] , offset : u64 ) -> io:: Result < usize > ;
41
61
@@ -51,8 +71,26 @@ pub trait FileExt {
51
71
/// When writing beyond the end of the file, the file is appropriately
52
72
/// extended and the intermediate bytes are initialized with the value 0.
53
73
///
54
- /// Note that similar to `File::write`, it is not an error to return a
74
+ /// Note that similar to [ `File::write`] , it is not an error to return a
55
75
/// short write.
76
+ ///
77
+ /// [`File::write`]: ../../../../std/fs/struct.File.html#write.v
78
+ ///
79
+ /// # Examples
80
+ ///
81
+ /// ```
82
+ /// use std::os::unix::prelude::FileExt;
83
+ /// use std::fs::File;
84
+ ///
85
+ /// # use std::io;
86
+ /// # fn f() -> io::Result<()> {
87
+ /// let file = File::open("foo.txt")?;
88
+ ///
89
+ /// // We now write at the offset 10.
90
+ /// file.write_at(b"sushi", 10)?;
91
+ /// # Ok(())
92
+ /// # }
93
+ /// ```
56
94
#[ stable( feature = "file_offset" , since = "1.15.0" ) ]
57
95
fn write_at ( & self , buf : & [ u8 ] , offset : u64 ) -> io:: Result < usize > ;
58
96
}
0 commit comments