(
source: &[T],
remaining_count: &mut usize,
remaining_bytes: &mut usize,
)
| 194 | } |
| 195 | |
| 196 | fn 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 | } |
no test coverage detected