about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFederico Ponzi <isaacisback92@gmail.com>2020-08-31 21:42:57 +0200
committerFederico Ponzi <isaacisback92@gmail.com>2020-08-31 23:20:56 +0200
commit7c1e5c1dcd25c945f619eda289f639dbe2b002da (patch)
tree271e6b2c959ce282eba340b4bcb500121ff4ab6a
parent2c9e27b759a9e9feeb943fb855e32d7383d1dcc6 (diff)
downloadrust-7c1e5c1dcd25c945f619eda289f639dbe2b002da.tar.gz
rust-7c1e5c1dcd25c945f619eda289f639dbe2b002da.zip
Update OpenOptions::as_flags docs, and minor styling
-rw-r--r--library/std/src/sys/unix/ext/fs.rs17
-rw-r--r--library/std/src/sys/unix/fs.rs1
2 files changed, 9 insertions, 9 deletions
diff --git a/library/std/src/sys/unix/ext/fs.rs b/library/std/src/sys/unix/ext/fs.rs
index 0a00c64e6c5..afda21d00e0 100644
--- a/library/std/src/sys/unix/ext/fs.rs
+++ b/library/std/src/sys/unix/ext/fs.rs
@@ -346,9 +346,13 @@ pub trait OpenOptionsExt {
     #[stable(feature = "open_options_ext", since = "1.10.0")]
     fn custom_flags(&mut self, flags: i32) -> &mut Self;
 
-    /// Get the flags of this OpenOptions as libc::c_int.
+    /// Get the flags of this OpenOptions as [`libc::c_int`].
+    /// With: [`libc::open`]
     ///
-    /// This method allows the reuse of the OpenOptions as flags argument for `libc::open()`.
+    /// This method allows the reuse of the OpenOptions as flags argument for [`fs::OpenOptions`].
+    ///
+    /// [`libc::c_int`]: https://docs.rs/libc/*/libc/type.c_int.html
+    /// [`libc::open`]: https://docs.rs/libc/*/libc/fn.open.html
     ///
     /// # Examples
     ///
@@ -359,16 +363,10 @@ pub trait OpenOptionsExt {
     /// use std::fs::OpenOptions;
     /// use std::os::unix::fs::OpenOptionsExt;
     ///
-    /// # fn main() {
     /// let mut options = OpenOptions::new();
     /// options.write(true).read(true);
-    /// if cfg!(unix) {
-    ///     options.custom_flags(libc::O_NOFOLLOW);
-    /// }
     /// let file_name = CString::new("foo.txt").unwrap();
-    /// let file = unsafe{ libc::open(file_name.as_c_str().as_ptr(), options.as_flags().unwrap()) };
-    ///
-    /// # }
+    /// let file = unsafe { libc::open(file_name.as_c_str().as_ptr(), options.as_flags().unwrap()) };
     /// ```
     #[stable(feature = "open_options_ext_as_flags", since = "1.47.0")]
     fn as_flags(&self) -> io::Result<libc::c_int>;
@@ -385,6 +383,7 @@ impl OpenOptionsExt for OpenOptions {
         self.as_inner_mut().custom_flags(flags);
         self
     }
+
     fn as_flags(&self) -> io::Result<libc::c_int> {
         self.as_inner().as_flags()
     }
diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs
index 13d8d59b034..1281fcc47bc 100644
--- a/library/std/src/sys/unix/fs.rs
+++ b/library/std/src/sys/unix/fs.rs
@@ -660,6 +660,7 @@ impl OpenOptions {
         let creation_mode = self.get_creation_mode()?;
         Ok(creation_mode | access_mode | self.custom_flags)
     }
+
     fn get_access_mode(&self) -> io::Result<c_int> {
         match (self.read, self.write, self.append) {
             (true, false, false) => Ok(libc::O_RDONLY),