Applies an Insert operation to create a new line. # Behavior 1. Checks if the branch ID already exists (error if so, unless duplicates allowed) 2. Validates the trunk exists and is alive 3. Resolves the insertion position (handling concurrent inserts) 4. Creates the branch entry in BRANCHES table 5. Updates TRUNK_BRANCHES ordering multimap 6. Applies any nested leaf operations # Errors - `Bran
(
txn: &mut T,
context: &mut ApplyContext,
trunk_id: TrunkId,
branch_id: BranchId,
after: Option<BranchId>,
leaf_ops: &[LeafOp],
content: &[u8],
)
| 185 | /// - `TrunkNotFound` - The parent trunk doesn't exist |
| 186 | /// - `InvalidTrunkState` - The parent trunk is deleted |
| 187 | fn apply_insert<T: MutCrdtTxnT>( |
| 188 | txn: &mut T, |
| 189 | context: &mut ApplyContext, |
| 190 | trunk_id: TrunkId, |
| 191 | branch_id: BranchId, |
| 192 | after: Option<BranchId>, |
| 193 | leaf_ops: &[LeafOp], |
| 194 | content: &[u8], |
| 195 | ) -> ApplyResult<()> { |
| 196 | // First apply the branch insert |
| 197 | apply_insert_only(txn, context, trunk_id, branch_id, after)?; |
| 198 | |
| 199 | // Then apply nested leaf operations |
| 200 | let mut leaf_idx: u32 = 0; |
| 201 | let mut _prev_leaf = None; |
| 202 | |
| 203 | for leaf_op in leaf_ops { |
| 204 | if let LeafOp::Insert { .. } = leaf_op { |
| 205 | let leaf_id = crate::crdt::LeafId::new(branch_id.change_id(), leaf_idx); |
| 206 | apply_leaf_op(txn, context, branch_id, leaf_id, leaf_op, content)?; |
| 207 | _prev_leaf = Some(leaf_id); |
| 208 | leaf_idx += 1; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | Ok(()) |
| 213 | } |
| 214 | |
| 215 | /// Applies an Insert operation without nested leaf operations. |
| 216 | fn apply_insert_only<T: MutCrdtTxnT>( |
no test coverage detected