1use std::path::PathBuf;
4use std::time::SystemTime;
5
6#[non_exhaustive]
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum DirEntryKind {
10 File,
11 Directory,
12 Symlink,
13}
14
15#[derive(Debug, Clone)]
19pub struct DirEntry {
20 pub name: String,
22 pub kind: DirEntryKind,
24 pub size: u64,
26 pub modified: Option<SystemTime>,
28 pub permissions: Option<u32>,
30 pub symlink_target: Option<PathBuf>,
32}
33
34impl DirEntry {
35 pub fn directory(name: impl Into<String>) -> Self {
37 Self {
38 name: name.into(),
39 kind: DirEntryKind::Directory,
40 size: 0,
41 modified: None,
42 permissions: None,
43 symlink_target: None,
44 }
45 }
46
47 pub fn file(name: impl Into<String>, size: u64) -> Self {
49 Self {
50 name: name.into(),
51 kind: DirEntryKind::File,
52 size,
53 modified: None,
54 permissions: None,
55 symlink_target: None,
56 }
57 }
58
59 pub fn symlink(name: impl Into<String>, target: impl Into<PathBuf>) -> Self {
61 Self {
62 name: name.into(),
63 kind: DirEntryKind::Symlink,
64 size: 0,
65 modified: None,
66 permissions: None,
67 symlink_target: Some(target.into()),
68 }
69 }
70
71 pub fn is_dir(&self) -> bool {
73 self.kind == DirEntryKind::Directory
74 }
75
76 pub fn is_file(&self) -> bool {
78 self.kind == DirEntryKind::File
79 }
80
81 pub fn is_symlink(&self) -> bool {
83 self.kind == DirEntryKind::Symlink
84 }
85}