MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / ChangeStore

Interface ChangeStore

atomic-core/src/change/store.rs:89–241  ·  view source on GitHub ↗

A trait for storing and retrieving changes. The primary operations are: - Loading complete changes by hash - Reading content bytes for specific vertices - Checking for change/content existence # Type Parameters Implementations define their own `Error` type, which must be convertible from `ChangeError` for change loading operations. # Thread Safety Implementations should be safe for concurrent

Source from the content-addressed store, hash-verified

87/// Implementations should be safe for concurrent read access. The trait
88/// methods take `&self`, enabling shared references across threads.
89pub trait ChangeStore: Send + Sync {
90 /// Error type for change store operations.
91 type Error: std::error::Error + Send + Sync + 'static;
92
93 /// Load a complete change by its hash.
94 ///
95 /// # Arguments
96 ///
97 /// * `hash` - The content hash of the change
98 ///
99 /// # Returns
100 ///
101 /// The complete [`Change`] if found.
102 ///
103 /// # Errors
104 ///
105 /// Returns an error if the change is not found or cannot be loaded.
106 fn get_change(&self, hash: &Hash) -> Result<Change, Self::Error>;
107
108 /// Check if a change exists.
109 ///
110 /// # Arguments
111 ///
112 /// * `hash` - The content hash of the change
113 ///
114 /// # Returns
115 ///
116 /// `true` if the change exists in the store.
117 fn has_change(&self, hash: &Hash) -> bool {
118 self.get_change(hash).is_ok()
119 }
120
121 /// Check if a change has content bytes.
122 ///
123 /// Some changes may have empty content sections (e.g., metadata-only changes).
124 ///
125 /// # Arguments
126 ///
127 /// * `hash` - The content hash of the change
128 ///
129 /// # Returns
130 ///
131 /// `true` if the change exists and has non-empty content.
132 fn has_contents(&self, hash: &Hash) -> bool {
133 self.get_change(hash)
134 .map(|c| !c.contents.is_empty())
135 .unwrap_or(false)
136 }
137
138 /// Read content bytes for a span.
139 ///
140 /// This is the core method for retrieving file content during output.
141 /// It reads the byte range `[span.start, span.end)` from the change
142 /// that introduced this span.
143 ///
144 /// # Arguments
145 ///
146 /// * `hash_fn` - Function to map `NodeId` to `Hash`

Callers 8

fromMethod · 0.50
test_error_debugFunction · 0.50
change_storeMethod · 0.50

Implementers 1

store.rsatomic-core/src/change/store.rs

Calls

no outgoing calls

Tested by

no test coverage detected