Applies a Replace operation to change a token's content. # Behavior 1. Verifies the leaf exists 2. Verifies the leaf is alive (not deleted) 3. Updates the leaf's content range to point to new content The leaf's ID is preserved, enabling accurate blame tracking. # Errors - `LeafNotFound` - The leaf doesn't exist - `InvalidLeafState` - The leaf is deleted
(
txn: &mut T,
context: &mut ApplyContext,
leaf_id: LeafId,
new_content: &[u8],
_content: &[u8],
)
| 266 | /// - `LeafNotFound` - The leaf doesn't exist |
| 267 | /// - `InvalidLeafState` - The leaf is deleted |
| 268 | fn apply_replace<T: MutCrdtTxnT>( |
| 269 | txn: &mut T, |
| 270 | context: &mut ApplyContext, |
| 271 | leaf_id: LeafId, |
| 272 | new_content: &[u8], |
| 273 | _content: &[u8], |
| 274 | ) -> ApplyResult<()> { |
| 275 | // Verify leaf exists |
| 276 | let leaf = txn |
| 277 | .get_leaf(leaf_id) |
| 278 | .map_err(|e| storage_err(e, "getting leaf"))? |
| 279 | .ok_or_else(|| ApplyError::leaf_not_found(leaf_id))?; |
| 280 | |
| 281 | // Check current state |
| 282 | if leaf.state().is_deleted() { |
| 283 | return Err(ApplyError::invalid_leaf_state( |
| 284 | leaf_id, "deleted", "replace", |
| 285 | )); |
| 286 | } |
| 287 | |
| 288 | // Update content range |
| 289 | // In a full implementation, we'd compute the actual offset in the content blob |
| 290 | let content_len = new_content.len() as u32; |
| 291 | let new_range = 0..content_len; |
| 292 | |
| 293 | txn.update_leaf_content(leaf_id, new_range) |
| 294 | .map_err(|e| storage_err(e, "updating leaf content"))?; |
| 295 | |
| 296 | context.record_leaf_replaced(); |
| 297 | context.record_content_bytes(content_len as u64); |
| 298 | Ok(()) |
| 299 | } |
| 300 | |
| 301 | // Restore Operation |
| 302 |
no test coverage detected