Skip to main content

engine/core/
object.rs

1//! Object kinds.
2//!
3//! The Engine models three kinds of objects: files, directories, and
4//! symbolic links. A file may carry real content (`Some(bytes)`) or be
5//! metadata-only (`None`). Detached namespaces are ordinary directories
6//! that are simply not reachable from the filesystem root.
7
8/// The kind of an Engine object.
9#[derive(Clone, Debug, PartialEq, Eq)]
10pub enum ObjectKind {
11    /// A file. `content` is `Some` when the file has modeled content and
12    /// `None` when it is metadata-only.
13    File {
14        /// The modeled content of the file, if any.
15        content: Option<Vec<u8>>,
16    },
17    /// A directory. Directories may contain other objects.
18    Directory,
19    /// A symbolic link: a pointer to another path.
20    ///
21    /// The target is stored as the link's own text, exactly as a real
22    /// filesystem stores it — a link is a file whose content is a path.
23    /// [`Engine::lookup`](crate::Engine::lookup) resolves links while
24    /// walking (with a depth cap), and the object's size is the length of
25    /// its target text, matching `stat` on a real link.
26    Symlink {
27        /// The target path, absolute (`/private/etc`) or relative to the
28        /// link's parent (`etc`), as the creating command wrote it.
29        target: String,
30    },
31}
32
33impl ObjectKind {
34    /// Returns `true` for files.
35    pub fn is_file(&self) -> bool {
36        matches!(self, Self::File { .. })
37    }
38
39    /// Returns `true` for directories.
40    pub fn is_directory(&self) -> bool {
41        matches!(self, Self::Directory)
42    }
43
44    /// Returns `true` for symbolic links.
45    pub fn is_symlink(&self) -> bool {
46        matches!(self, Self::Symlink { .. })
47    }
48}