Skip to content

Commit 0f6e010

Browse files
Rollup merge of #45582 - GuillaumeGomez:doc-unix-missing-links, r=frewsxcv
Add missing links and examples r? @rust-lang/docs
2 parents e177df3 + cef0573 commit 0f6e010

File tree

1 file changed

+70
-4
lines changed
  • src/libstd/sys/unix/ext

1 file changed

+70
-4
lines changed

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

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ use sys;
2020
use sys_common::{FromInner, AsInner, AsInnerMut};
2121
use sys::platform::fs::MetadataExt as UnixMetadataExt;
2222

23-
/// Unix-specific extensions to `File`
23+
/// Unix-specific extensions to [`File`].
24+
///
25+
/// [`File`]: ../../../../std/fs/struct.File.html
2426
#[stable(feature = "file_offset", since = "1.15.0")]
2527
pub trait FileExt {
2628
/// Reads a number of bytes starting from a given offset.
@@ -515,19 +517,79 @@ impl MetadataExt for fs::Metadata {
515517
fn blocks(&self) -> u64 { self.st_blocks() }
516518
}
517519

518-
/// Add special unix types (block/char device, fifo and socket)
520+
/// Add support for special unix types (block/char device, fifo and socket).
519521
#[stable(feature = "file_type_ext", since = "1.5.0")]
520522
pub trait FileTypeExt {
521523
/// Returns whether this file type is a block device.
524+
///
525+
/// # Examples
526+
///
527+
/// ```
528+
/// use std::fs;
529+
/// use std::os::unix::fs::FileTypeExt;
530+
///
531+
/// # use std::io;
532+
/// # fn f() -> io::Result<()> {
533+
/// let meta = fs::metadata("block_device_file")?;
534+
/// let file_type = meta.file_type();
535+
/// assert!(file_type.is_block_device());
536+
/// # Ok(())
537+
/// # }
538+
/// ```
522539
#[stable(feature = "file_type_ext", since = "1.5.0")]
523540
fn is_block_device(&self) -> bool;
524541
/// Returns whether this file type is a char device.
542+
///
543+
/// # Examples
544+
///
545+
/// ```
546+
/// use std::fs;
547+
/// use std::os::unix::fs::FileTypeExt;
548+
///
549+
/// # use std::io;
550+
/// # fn f() -> io::Result<()> {
551+
/// let meta = fs::metadata("char_device_file")?;
552+
/// let file_type = meta.file_type();
553+
/// assert!(file_type.is_char_device());
554+
/// # Ok(())
555+
/// # }
556+
/// ```
525557
#[stable(feature = "file_type_ext", since = "1.5.0")]
526558
fn is_char_device(&self) -> bool;
527559
/// Returns whether this file type is a fifo.
560+
///
561+
/// # Examples
562+
///
563+
/// ```
564+
/// use std::fs;
565+
/// use std::os::unix::fs::FileTypeExt;
566+
///
567+
/// # use std::io;
568+
/// # fn f() -> io::Result<()> {
569+
/// let meta = fs::metadata("fifo_file")?;
570+
/// let file_type = meta.file_type();
571+
/// assert!(file_type.is_fifo());
572+
/// # Ok(())
573+
/// # }
574+
/// ```
528575
#[stable(feature = "file_type_ext", since = "1.5.0")]
529576
fn is_fifo(&self) -> bool;
530577
/// Returns whether this file type is a socket.
578+
///
579+
/// # Examples
580+
///
581+
/// ```
582+
/// use std::fs;
583+
/// use std::os::unix::fs::FileTypeExt;
584+
///
585+
/// # use std::io;
586+
/// # fn f() -> io::Result<()> {
587+
/// let meta = fs::metadata("unix.socket")?;
588+
/// let file_type = meta.file_type();
589+
/// assert!(file_type.is_socket());
590+
/// # Ok(())
591+
/// # }
592+
/// ```
531593
#[stable(feature = "file_type_ext", since = "1.5.0")]
532594
fn is_socket(&self) -> bool;
533595
}
@@ -540,7 +602,9 @@ impl FileTypeExt for fs::FileType {
540602
fn is_socket(&self) -> bool { self.as_inner().is(libc::S_IFSOCK) }
541603
}
542604

543-
/// Unix-specific extension methods for `fs::DirEntry`
605+
/// Unix-specific extension methods for [`fs::DirEntry`].
606+
///
607+
/// [`fs::DirEntry`]: ../../../../std/fs/struct.DirEntry.html
544608
#[stable(feature = "dir_entry_ext", since = "1.1.0")]
545609
pub trait DirEntryExt {
546610
/// Returns the underlying `d_ino` field in the contained `dirent`
@@ -600,7 +664,9 @@ pub fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()>
600664
}
601665

602666
#[stable(feature = "dir_builder", since = "1.6.0")]
603-
/// An extension trait for `fs::DirBuilder` for unix-specific options.
667+
/// An extension trait for [`fs::DirBuilder`] for unix-specific options.
668+
///
669+
/// [`fs::DirBuilder`]: ../../../../std/fs/struct.DirBuilder.html
604670
pub trait DirBuilderExt {
605671
/// Sets the mode to create new directories with. This option defaults to
606672
/// 0o777.

0 commit comments

Comments
 (0)