liteboxfs 0.2.0

A modern POSIX filesystem in a SQLite database
Documentation
use crate::block::FileId as StoreFileId;

/// A file ID that has been COW-materialized for a specific root.
///
/// This type can only be constructed by [`SqlStore::materialize_file`], which ensures the
/// underlying `liteboxfs_files` row is private to the current root before any mutation. Mutation
/// methods on [`SqlStore`] require this type instead of a bare [`StoreFileId`], making it
/// impossible to forget the materialization step.
///
/// [`SqlStore`]: super::SqlStore
/// [`SqlStore::materialize_file`]: super::SqlStore::materialize_file
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ExclusiveFileId(StoreFileId);

impl ExclusiveFileId {
    pub(in crate::sql) fn new(id: StoreFileId) -> Self {
        Self(id)
    }

    /// The underlying file ID after materialization.
    ///
    /// Callers outside the `sql` module use this to keep their own `file_id` cache in sync after
    /// materialization may have assigned a new row.
    pub fn file_id(self) -> StoreFileId {
        self.0
    }
}

impl rusqlite::ToSql for ExclusiveFileId {
    fn to_sql(&self) -> rusqlite::Result<rusqlite::types::ToSqlOutput<'_>> {
        self.0.to_sql()
    }
}