aboutsummaryrefslogtreecommitdiff
path: root/src/fs/os/unix/dir_entry_ext.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/os/unix/dir_entry_ext.rs')
-rw-r--r--src/fs/os/unix/dir_entry_ext.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/fs/os/unix/dir_entry_ext.rs b/src/fs/os/unix/dir_entry_ext.rs
new file mode 100644
index 0000000..2ac56da
--- /dev/null
+++ b/src/fs/os/unix/dir_entry_ext.rs
@@ -0,0 +1,44 @@
+use crate::fs::DirEntry;
+use std::os::unix::fs::DirEntryExt as _;
+
+/// Unix-specific extension methods for [`fs::DirEntry`].
+///
+/// This mirrors the definition of [`std::os::unix::fs::DirEntryExt`].
+///
+/// [`fs::DirEntry`]: crate::fs::DirEntry
+/// [`std::os::unix::fs::DirEntryExt`]: std::os::unix::fs::DirEntryExt
+pub trait DirEntryExt: sealed::Sealed {
+ /// Returns the underlying `d_ino` field in the contained `dirent`
+ /// structure.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use tokio::fs;
+ /// use tokio::fs::os::unix::DirEntryExt;
+ ///
+ /// # #[tokio::main]
+ /// # async fn main() -> std::io::Result<()> {
+ /// let mut entries = fs::read_dir(".").await?;
+ /// while let Some(entry) = entries.next_entry().await? {
+ /// // Here, `entry` is a `DirEntry`.
+ /// println!("{:?}: {}", entry.file_name(), entry.ino());
+ /// }
+ /// # Ok(())
+ /// # }
+ /// ```
+ fn ino(&self) -> u64;
+}
+
+impl DirEntryExt for DirEntry {
+ fn ino(&self) -> u64 {
+ self.as_inner().ino()
+ }
+}
+
+impl sealed::Sealed for DirEntry {}
+
+pub(crate) mod sealed {
+ #[doc(hidden)]
+ pub trait Sealed {}
+}