ralph_workflow/workspace/dir_entry.rs
1// DirEntry - abstraction for directory entries.
2//
3// This file is included by workspace.rs via include!().
4
5/// A directory entry returned by `Workspace::read_dir`.
6///
7/// This abstracts `std::fs::DirEntry` to allow in-memory implementations.
8#[derive(Debug, Clone)]
9pub struct DirEntry {
10 /// The path of this entry (relative to workspace root).
11 path: PathBuf,
12 /// Whether this entry is a file.
13 is_file: bool,
14 /// Whether this entry is a directory.
15 is_dir: bool,
16 /// Optional modification time (for sorting by recency).
17 modified: Option<std::time::SystemTime>,
18}
19
20impl DirEntry {
21 /// Create a new directory entry.
22 #[must_use]
23 pub const fn new(path: PathBuf, is_file: bool, is_dir: bool) -> Self {
24 Self {
25 path,
26 is_file,
27 is_dir,
28 modified: None,
29 }
30 }
31
32 /// Create a new directory entry with modification time.
33 #[must_use]
34 pub const fn with_modified(
35 path: PathBuf,
36 is_file: bool,
37 is_dir: bool,
38 modified: std::time::SystemTime,
39 ) -> Self {
40 Self {
41 path,
42 is_file,
43 is_dir,
44 modified: Some(modified),
45 }
46 }
47
48 /// Get the path of this entry.
49 #[must_use]
50 pub fn path(&self) -> &Path {
51 &self.path
52 }
53
54 /// Check if this entry is a file.
55 #[must_use]
56 pub const fn is_file(&self) -> bool {
57 self.is_file
58 }
59
60 /// Check if this entry is a directory.
61 #[must_use]
62 pub const fn is_dir(&self) -> bool {
63 self.is_dir
64 }
65
66 /// Get the file name of this entry.
67 #[must_use]
68 pub fn file_name(&self) -> Option<&std::ffi::OsStr> {
69 self.path.file_name()
70 }
71
72 /// Get the modification time of this entry, if available.
73 #[must_use]
74 pub const fn modified(&self) -> Option<std::time::SystemTime> {
75 self.modified
76 }
77}