ailloli_ui_fs/capabilities.rs
1//! Provider feature flags used to gate filesystem UI actions.
2
3/// Operations advertised by a filesystem provider.
4///
5/// Every boolean means that the corresponding operation is intended to be
6/// available. Capabilities are informational: trait default methods do not
7/// consult them, and an advertised operation can still fail for a resource.
8///
9/// # Examples
10///
11/// ```
12/// use ailloli_ui_fs::FileCapabilities;
13/// assert!(FileCapabilities::READ_ONLY.read);
14/// assert!(!FileCapabilities::READ_ONLY.write);
15/// ```
16#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
17pub struct FileCapabilities {
18 /// Directory listing, file reads, and metadata queries are available.
19 pub read: bool,
20 /// File content writes are available.
21 pub write: bool,
22 /// Directory creation is available.
23 pub create_dir: bool,
24 /// Same-provider rename is available.
25 pub rename: bool,
26 /// Non-recursive removal is available.
27 pub remove: bool,
28 /// Entry copy is available, either natively or through the trait default.
29 pub copy_entry: bool,
30 /// Entry move is available, either natively or as rename.
31 pub move_entry: bool,
32 /// Recursive removal is available, either natively or through the trait default.
33 pub remove_recursive: bool,
34 /// Native directory watch events are available.
35 pub watch: bool,
36}
37
38impl FileCapabilities {
39 /// Read-only profile: only `read` is `true`.
40 ///
41 /// # Examples
42 ///
43 /// ```
44 /// use ailloli_ui_fs::FileCapabilities;
45 /// assert_eq!(FileCapabilities::READ_ONLY, FileCapabilities::default());
46 /// ```
47 pub const READ_ONLY: Self = Self {
48 read: true,
49 write: false,
50 create_dir: false,
51 rename: false,
52 remove: false,
53 copy_entry: false,
54 move_entry: false,
55 remove_recursive: false,
56 watch: false,
57 };
58
59 /// Read/write profile with mutation and recursive helpers, but no watch.
60 ///
61 /// # Examples
62 ///
63 /// ```
64 /// use ailloli_ui_fs::FileCapabilities;
65 /// assert!(FileCapabilities::READ_WRITE.remove_recursive);
66 /// assert!(!FileCapabilities::READ_WRITE.watch);
67 /// ```
68 pub const READ_WRITE: Self = Self {
69 read: true,
70 write: true,
71 create_dir: true,
72 rename: true,
73 remove: true,
74 copy_entry: true,
75 move_entry: true,
76 remove_recursive: true,
77 watch: false,
78 };
79}
80
81impl Default for FileCapabilities {
82 fn default() -> Self {
83 Self::READ_ONLY
84 }
85}