gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81414 Sutichaykuna

add get_disjoint_node_context_mut to tree (#596)

* disjoint

* Update RELEASES.md

77b704eb45705705e970eeb7d3645c906f5e8931 · ruwaq Dylan Blokhuis · (2 wata ñawpaq) · tayta a2d982980 · kay commitpi sach'ata qhaway

Semántico sayk'uy · 1

src/tree/taffy_tree.rs

2 qillqakuna · +9 −0

diff --git a/RELEASES.md b/RELEASES.md
index ea435e825..c52dadb4a 100644
--- a/RELEASES.md
+++ b/RELEASES.md
@@ -93,6 +93,7 @@ Example usage change:
   - `compute_leaf_layout`
   - `compute_hidden_layout`
 - Added `insert_child_at_index()` method to the `Taffy` tree. This can be used to insert a child node at any position instead of just the end.
+- Added `get_disjoint_node_context_mut()` method to the `Taffy` tree. This can be used to safely get multiple mutable borrows at the same time.
 
 ### Removed
 
diff --git a/src/tree/taffy_tree.rs b/src/tree/taffy_tree.rs
index 13ecc386a..681328ec9 100644
--- a/src/tree/taffy_tree.rs
+++ b/src/tree/taffy_tree.rs
@@ -476,6 +476,14 @@ impl<NodeContext> TaffyTree<NodeContext> {
         self.node_context_data.get_mut(node.into())
     }
 
+    /// Gets mutable references to the the context data associated with the nodes. All keys must be valid and disjoint, otherwise None is returned.
+    pub fn get_disjoint_node_context_mut<const N: usize>(
+        &mut self,
+        keys: [NodeId; N],
+    ) -> Option<[&mut NodeContext; N]> {
+        self.node_context_data.get_disjoint_mut(keys.map(|k| k.into()))
+    }
+
     /// Adds a `child` node under the supplied `parent`
     pub fn add_child(&mut self, parent: NodeId, child: NodeId) -> TaffyResult<()> {
         let parent_key = parent.into();