Skip to main content

continuity_buffer/
metadata.rs

1//! Buffer metadata that is not part of the rope text.
2//!
3//! The editor core thread owns this metadata alongside the buffer rope.
4
5use std::path::PathBuf;
6
7/// Association between a buffer and an imported/exported filesystem path.
8///
9/// **Thread ownership**: stored on [`crate::Buffer`] and mutated only by the
10/// editor core thread. Other threads receive cloned snapshots of this value.
11#[derive(Clone, Debug, PartialEq, Eq)]
12pub struct FileAssociation {
13    /// Path this buffer saves back to.
14    pub path: PathBuf,
15    /// Last observed file modification time, in Unix milliseconds.
16    pub mtime_ms: i64,
17    /// FNV-1a hash of the last imported/saved raw file bytes.
18    pub hash: u64,
19    /// FNV-1a hash of the decoded text content last imported/saved.
20    pub content_hash: u64,
21}
22
23impl FileAssociation {
24    /// Build a file association from path + observed metadata.
25    #[must_use]
26    pub fn new(path: PathBuf, mtime_ms: i64, hash: u64) -> Self {
27        Self {
28            path,
29            mtime_ms,
30            hash,
31            content_hash: hash,
32        }
33    }
34
35    /// Return this file association with an explicit decoded-content hash.
36    #[must_use]
37    pub fn with_content_hash(mut self, content_hash: u64) -> Self {
38        self.content_hash = content_hash;
39        self
40    }
41}