Struct cap_std::fs::DirEntry

source ·
pub struct DirEntry { /* private fields */ }
Expand description

Entries returned by the ReadDir iterator.

This corresponds to std::fs::DirEntry.

Unlike std::fs::DirEntry, this API has no DirEntry::path, because absolute paths don’t interoperate well with the capability model.

There is a file_name function, however there are also open, open_with, open_dir, remove_file, and remove_dir functions for opening or removing the entry directly, which can be more efficient and convenient.

There is no from_std method, as std::fs::DirEntry doesn’t provide a way to construct a DirEntry without opening directories by ambient paths.

Implementations§

Open the file for reading.

Examples found in repository?
src/fs_utf8/dir_entry.rs (line 36)
35
36
37
    pub fn open(&self) -> io::Result<File> {
        self.cap_std.open().map(File::from_cap_std)
    }

Open the file with the given options.

Examples found in repository?
src/fs_utf8/dir_entry.rs (line 42)
41
42
43
    pub fn open_with(&self, options: &OpenOptions) -> io::Result<File> {
        self.cap_std.open_with(options).map(File::from_cap_std)
    }

Open the entry as a directory.

Examples found in repository?
src/fs_utf8/dir_entry.rs (line 48)
47
48
49
    pub fn open_dir(&self) -> io::Result<Dir> {
        self.cap_std.open_dir().map(Dir::from_cap_std)
    }

Removes the file from its filesystem.

Examples found in repository?
src/fs_utf8/dir_entry.rs (line 54)
53
54
55
    pub fn remove_file(&self) -> io::Result<()> {
        self.cap_std.remove_file()
    }

Removes the directory from its filesystem.

Examples found in repository?
src/fs_utf8/dir_entry.rs (line 60)
59
60
61
    pub fn remove_dir(&self) -> io::Result<()> {
        self.cap_std.remove_dir()
    }

Returns the metadata for the file that this entry points at.

This corresponds to std::fs::DirEntry::metadata.

Examples found in repository?
src/fs_utf8/dir_entry.rs (line 68)
67
68
69
    pub fn metadata(&self) -> io::Result<Metadata> {
        self.cap_std.metadata()
    }

Returns the file type for the file that this entry points at.

This corresponds to std::fs::DirEntry::file_type.

Examples found in repository?
src/fs_utf8/dir_entry.rs (line 76)
75
76
77
    pub fn file_type(&self) -> io::Result<FileType> {
        self.cap_std.file_type()
    }

Returns the bare file name of this directory entry without any other leading path component.

This corresponds to std::fs::DirEntry::file_name.

Examples found in repository?
src/fs_utf8/dir_entry.rs (line 91)
90
91
92
    pub fn file_name(&self) -> io::Result<String> {
        Ok(to_utf8(self.cap_std.file_name())?.into())
    }

Trait Implementations§

Formats the value using the given formatter. Read more
Returns the underlying d_ino field in the contained dirent structure. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.