Translate existing semantic identities while preserving ROOT placeholders.
(
&mut self,
mut remap: impl FnMut(crate::types::NodeId) -> Result<crate::types::NodeId, E>,
)
| 323 | |
| 324 | /// Translate existing semantic identities while preserving ROOT placeholders. |
| 325 | pub fn remap_referenced_node_ids<E>( |
| 326 | &mut self, |
| 327 | mut remap: impl FnMut(crate::types::NodeId) -> Result<crate::types::NodeId, E>, |
| 328 | ) -> Result<(), E> { |
| 329 | fn trunk<E>( |
| 330 | id: &mut TrunkId, |
| 331 | f: &mut impl FnMut(crate::types::NodeId) -> Result<crate::types::NodeId, E>, |
| 332 | ) -> Result<(), E> { |
| 333 | if !id.change_id().is_root() { |
| 334 | *id = TrunkId::new(f(id.change_id())?, id.file_idx()); |
| 335 | } |
| 336 | Ok(()) |
| 337 | } |
| 338 | fn branch<E>( |
| 339 | id: &mut BranchId, |
| 340 | f: &mut impl FnMut(crate::types::NodeId) -> Result<crate::types::NodeId, E>, |
| 341 | ) -> Result<(), E> { |
| 342 | if !id.change_id().is_root() { |
| 343 | *id = BranchId::new(f(id.change_id())?, id.branch_idx()); |
| 344 | } |
| 345 | Ok(()) |
| 346 | } |
| 347 | fn leaf<E>( |
| 348 | id: &mut LeafId, |
| 349 | f: &mut impl FnMut(crate::types::NodeId) -> Result<crate::types::NodeId, E>, |
| 350 | ) -> Result<(), E> { |
| 351 | if !id.change_id().is_root() { |
| 352 | *id = LeafId::new(f(id.change_id())?, id.leaf_idx()); |
| 353 | } |
| 354 | Ok(()) |
| 355 | } |
| 356 | fn leaves<E>( |
| 357 | ops: &mut [LeafOp], |
| 358 | f: &mut impl FnMut(crate::types::NodeId) -> Result<crate::types::NodeId, E>, |
| 359 | ) -> Result<(), E> { |
| 360 | for op in ops { |
| 361 | match op { |
| 362 | LeafOp::Insert { |
| 363 | after: Some(id), .. |
| 364 | } => leaf(id, f)?, |
| 365 | LeafOp::Delete { leaf: id } |
| 366 | | LeafOp::Replace { leaf: id, .. } |
| 367 | | LeafOp::Restore { leaf: id } => leaf(id, f)?, |
| 368 | LeafOp::Insert { after: None, .. } => {} |
| 369 | } |
| 370 | } |
| 371 | Ok(()) |
| 372 | } |
| 373 | trunk(&mut self.trunk_id, &mut remap)?; |
| 374 | match &mut self.trunk_op { |
| 375 | Some(TrunkOp::Delete { trunk: id }) |
| 376 | | Some(TrunkOp::Move { trunk: id, .. }) |
| 377 | | Some(TrunkOp::Undelete { trunk: id }) |
| 378 | | Some(TrunkOp::SetMode { trunk: id, .. }) |
| 379 | | Some(TrunkOp::SetKind { trunk: id, .. }) => trunk(id, &mut remap)?, |
| 380 | Some(TrunkOp::Create { .. } | TrunkOp::ProjectedSpanEdit { .. }) | None => {} |
| 381 | } |
| 382 | for line in &mut self.line_ops { |
no test coverage detected