pub struct DirEntry {
pub name: String,
pub path: PathBuf,
pub file_type: FileType,
pub size: u64,
pub inode: u64,
}Expand description
A single entry from a directory listing.
Returned by FsDir::read_dir via ReadDirIter.
Contains basic information about each item in a directory.
§Fields
| Field | Type | Description |
|---|---|---|
name | String | Filename only (not full path) |
path | PathBuf | Full absolute path |
file_type | FileType | File, Directory, or Symlink |
size | u64 | Size in bytes |
inode | u64 | Inode number |
§Example
use anyfs_backend::{DirEntry, FileType};
use std::path::PathBuf;
let entry = DirEntry {
name: "readme.md".to_string(),
path: PathBuf::from("/docs/readme.md"),
file_type: FileType::File,
size: 2048,
inode: 123,
};
assert_eq!(entry.name, "readme.md");
assert_eq!(entry.file_type, FileType::File);§Usage with read_dir
use anyfs_backend::Fs;
use std::path::Path;
// Generic function that works with any Fs implementation
fn list_files<B: Fs>(fs: &B) -> Result<(), anyfs_backend::FsError> {
for entry in fs.read_dir(Path::new("/"))? {
let entry = entry?;
println!("{} ({:?}, {} bytes)", entry.name, entry.file_type, entry.size);
}
Ok(())
}Fields§
§name: StringName of the entry (filename only, not full path).
path: PathBufFull path to the entry.
file_type: FileTypeType of the entry.
size: u64Size in bytes.
inode: u64Inode number.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DirEntry
impl RefUnwindSafe for DirEntry
impl Send for DirEntry
impl Sync for DirEntry
impl Unpin for DirEntry
impl UnwindSafe for DirEntry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more