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

Function bounded_operations

atomic-repository/src/patch_evidence.rs:196–219  ·  view source on GitHub ↗
(
    source: &[T],
    remaining_count: &mut usize,
    remaining_bytes: &mut usize,
)

Source from the content-addressed store, hash-verified

194}
195
196fn bounded_operations<T: Clone + Serialize>(
197 source: &[T],
198 remaining_count: &mut usize,
199 remaining_bytes: &mut usize,
200) -> Result<RecordedOperations<T>, RepositoryError> {
201 let mut operations = Vec::new();
202 for operation in source.iter().take(*remaining_count) {
203 let mut budget = ByteBudget(*remaining_bytes);
204 if let Err(error) = serde_json::to_writer(&mut budget, operation) {
205 if error.is_io() {
206 break;
207 }
208 return Err(RepositoryError::Serialization(error.to_string()));
209 }
210 *remaining_bytes = budget.0;
211 operations.push(operation.clone());
212 }
213 *remaining_count -= operations.len();
214 Ok(RecordedOperations {
215 truncated: operations.len() < source.len(),
216 operations,
217 total: source.len(),
218 })
219}

Callers 1

patch_evidenceMethod · 0.85

Calls 6

ByteBudgetClass · 0.85
iterMethod · 0.45
is_ioMethod · 0.45
pushMethod · 0.45
cloneMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected