Skip to content

Commit c09adc4

Browse files
Add missing links and examples for FileExt
1 parent 69ee5a8 commit c09adc4

File tree

1 file changed

+40
-2
lines changed
  • src/libstd/sys/unix/ext

1 file changed

+40
-2
lines changed

src/libstd/sys/unix/ext/fs.rs

+40-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,28 @@ pub trait FileExt {
3434
///
3535
/// The current file cursor is not affected by this function.
3636
///
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
3838
/// 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+
/// ```
3959
#[stable(feature = "file_offset", since = "1.15.0")]
4060
fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result<usize>;
4161

@@ -51,8 +71,26 @@ pub trait FileExt {
5171
/// When writing beyond the end of the file, the file is appropriately
5272
/// extended and the intermediate bytes are initialized with the value 0.
5373
///
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
5575
/// 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+
/// ```
5694
#[stable(feature = "file_offset", since = "1.15.0")]
5795
fn write_at(&self, buf: &[u8], offset: u64) -> io::Result<usize>;
5896
}

0 commit comments

Comments
 (0)