Skip to content

Commit 7c1e5c1

Browse files
author
Federico Ponzi
committed
Update OpenOptions::as_flags docs, and minor styling
1 parent 2c9e27b commit 7c1e5c1

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

library/std/src/sys/unix/ext/fs.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,13 @@ pub trait OpenOptionsExt {
346346
#[stable(feature = "open_options_ext", since = "1.10.0")]
347347
fn custom_flags(&mut self, flags: i32) -> &mut Self;
348348

349-
/// Get the flags of this OpenOptions as libc::c_int.
349+
/// Get the flags of this OpenOptions as [`libc::c_int`].
350+
/// With: [`libc::open`]
350351
///
351-
/// This method allows the reuse of the OpenOptions as flags argument for `libc::open()`.
352+
/// This method allows the reuse of the OpenOptions as flags argument for [`fs::OpenOptions`].
353+
///
354+
/// [`libc::c_int`]: https://docs.rs/libc/*/libc/type.c_int.html
355+
/// [`libc::open`]: https://docs.rs/libc/*/libc/fn.open.html
352356
///
353357
/// # Examples
354358
///
@@ -359,16 +363,10 @@ pub trait OpenOptionsExt {
359363
/// use std::fs::OpenOptions;
360364
/// use std::os::unix::fs::OpenOptionsExt;
361365
///
362-
/// # fn main() {
363366
/// let mut options = OpenOptions::new();
364367
/// options.write(true).read(true);
365-
/// if cfg!(unix) {
366-
/// options.custom_flags(libc::O_NOFOLLOW);
367-
/// }
368368
/// let file_name = CString::new("foo.txt").unwrap();
369-
/// let file = unsafe{ libc::open(file_name.as_c_str().as_ptr(), options.as_flags().unwrap()) };
370-
///
371-
/// # }
369+
/// let file = unsafe { libc::open(file_name.as_c_str().as_ptr(), options.as_flags().unwrap()) };
372370
/// ```
373371
#[stable(feature = "open_options_ext_as_flags", since = "1.47.0")]
374372
fn as_flags(&self) -> io::Result<libc::c_int>;
@@ -385,6 +383,7 @@ impl OpenOptionsExt for OpenOptions {
385383
self.as_inner_mut().custom_flags(flags);
386384
self
387385
}
386+
388387
fn as_flags(&self) -> io::Result<libc::c_int> {
389388
self.as_inner().as_flags()
390389
}

library/std/src/sys/unix/fs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,7 @@ impl OpenOptions {
660660
let creation_mode = self.get_creation_mode()?;
661661
Ok(creation_mode | access_mode | self.custom_flags)
662662
}
663+
663664
fn get_access_mode(&self) -> io::Result<c_int> {
664665
match (self.read, self.write, self.append) {
665666
(true, false, false) => Ok(libc::O_RDONLY),

0 commit comments

Comments
 (0)