Skip to main content

## DirEntryExt2

# Trait DirEntryExt2

Source

    pub trait DirEntryExt2 {
        // Required method
        fn file_name_ref(&self) -> &OsStr;
    }

🔬This is a nightly-only experimental API. (`dir_entry_ext2` #85573)
Available on Unix only.
Expand description

Sealed Unix-specific extension methods for `fs::DirEntry`.

This trait cannot be implemented outside `std`.

## Required Methods§

Source

#### fn file_name_ref(&self) -> &OsStr

🔬This is a nightly-only experimental API. (`dir_entry_ext2` #85573)

Returns a reference to the underlying `OsStr` of this entry’s filename.

##### §Examples

    #![feature(dir_entry_ext2)]
    use std::os::unix::fs::DirEntryExt2;
    use std::{fs, io};

    fn main() -> io::Result<()> {
        let mut entries = fs::read_dir(".")?.collect::<Result<Vec<_>, io::Error>>()?;
        entries.sort_unstable_by(|a, b| a.file_name_ref().cmp(b.file_name_ref()));

        for p in entries {
            println!("{p:?}");
        }

        Ok(())
    }

## Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

## Implementors§

Source§

### impl DirEntryExt2 for DirEntry