vce-engine 0.1.1

The generic state substrate of the Virtual Computing Engine (VCE)
Documentation
//! Object kinds.
//!
//! The Engine models three kinds of objects: files, directories, and
//! symbolic links. A file may carry real content (`Some(bytes)`) or be
//! metadata-only (`None`). Detached namespaces are ordinary directories
//! that are simply not reachable from the filesystem root.

/// The kind of an Engine object.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ObjectKind {
    /// A file. `content` is `Some` when the file has modeled content and
    /// `None` when it is metadata-only.
    File {
        /// The modeled content of the file, if any.
        content: Option<Vec<u8>>,
    },
    /// A directory. Directories may contain other objects.
    Directory,
    /// A symbolic link: a pointer to another path.
    ///
    /// The target is stored as the link's own text, exactly as a real
    /// filesystem stores it — a link is a file whose content is a path.
    /// [`Engine::lookup`](crate::Engine::lookup) resolves links while
    /// walking (with a depth cap), and the object's size is the length of
    /// its target text, matching `stat` on a real link.
    Symlink {
        /// The target path, absolute (`/private/etc`) or relative to the
        /// link's parent (`etc`), as the creating command wrote it.
        target: String,
    },
}

impl ObjectKind {
    /// Returns `true` for files.
    pub fn is_file(&self) -> bool {
        matches!(self, Self::File { .. })
    }

    /// Returns `true` for directories.
    pub fn is_directory(&self) -> bool {
        matches!(self, Self::Directory)
    }

    /// Returns `true` for symbolic links.
    pub fn is_symlink(&self) -> bool {
        matches!(self, Self::Symlink { .. })
    }
}