tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5544Rust 88Markdown 11TOML 91926 Sutichaykuna

Make `slotmap` dependency compatible with `no_std` environments (#594)

* unify `std` features of `taffy` and `slotmap`

* use appropriate map for `no_std`

* add release note

* pass rustfmt check

440843c700455363383e0a4fc365a15deebd4717 · ruwaq Conall Keane · (2 wata ñawpaq) · tayta 03b513210 · kay commitpi sach'ata qhaway

Semántico sayk'uy · 2

src/tree/taffy_tree.rs

3 qillqakuna · +10 −5

diff --git a/Cargo.toml b/Cargo.toml
index 348f79457..c20c13834 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -18,7 +18,7 @@ license = "MIT"
 arrayvec = { version = "0.7", default-features = false }
 num-traits = { version = "0.2", default-features = false }
 serde = { version = "1.0", default-features = false, optional = true, features = ["serde_derive"] }
-slotmap = { version = "1.0.6", optional = true }
+slotmap = { version = "1.0.6", default-features = false, optional = true }
 grid = { version = "0.12.0", default-features = false, optional = true }
 
 ### FEATURES #################################################################
@@ -47,7 +47,7 @@ taffy_tree = ["dep:slotmap"]
 # Add serde derives to Style structs
 serde = ["dep:serde"]
 # Allow Taffy to depend on the standard library
-std = ["num-traits/std", "grid?/std", "serde?/std"]
+std = ["num-traits/std", "grid?/std", "serde?/std", "slotmap?/std"]
 # Allow Taffy to depend on the alloc library
 alloc = ["serde?/alloc"]
 # Internal featyre for debugging
diff --git a/RELEASES.md b/RELEASES.md
index 5926e857c..ea435e825 100644
--- a/RELEASES.md
+++ b/RELEASES.md
@@ -111,6 +111,7 @@ Example usage change:
   - All types from the `node`, `data`, `layout`, `error` and `cache` modules have been moved to the  the `tree` module.
 - Fixed misspelling: `RunMode::PeformLayout` renamed into `RunMode::PerformLayout` (added missing `r`).
 - `serde` dependency has been made compatible with `no_std` environments
+- `slotmap` dependency has been made compatible with `no_std` environments
 
 ## 0.3.18
 
diff --git a/src/tree/taffy_tree.rs b/src/tree/taffy_tree.rs
index 5462c4b9d..13ecc386a 100644
--- a/src/tree/taffy_tree.rs
+++ b/src/tree/taffy_tree.rs
@@ -1,5 +1,9 @@
 //! Contains [TaffyTree](crate::tree::TaffyTree): the default implementation of [LayoutTree](crate::tree::LayoutTree), and the error type for Taffy.
-use slotmap::{DefaultKey, SlotMap, SparseSecondaryMap};
+#[cfg(not(feature = "std"))]
+use slotmap::SecondaryMap;
+#[cfg(feature = "std")]
+use slotmap::SparseSecondaryMap as SecondaryMap;
+use slotmap::{DefaultKey, SlotMap};
 
 use crate::geometry::Size;
 use crate::style::{AvailableSpace, Display, Style};
@@ -125,7 +129,7 @@ pub struct TaffyTree<NodeContext = ()> {
     nodes: SlotMap<DefaultKey, NodeData>,
 
     /// Functions/closures that compute the intrinsic size of leaf nodes
-    node_context_data: SparseSecondaryMap<DefaultKey, NodeContext>,
+    node_context_data: SecondaryMap<DefaultKey, NodeContext>,
 
     /// The children of each node
     ///
@@ -360,7 +364,7 @@ impl<NodeContext> TaffyTree<NodeContext> {
             nodes: SlotMap::with_capacity(capacity),
             children: SlotMap::with_capacity(capacity),
             parents: SlotMap::with_capacity(capacity),
-            node_context_data: SparseSecondaryMap::with_capacity(capacity),
+            node_context_data: SecondaryMap::with_capacity(capacity),
             config: TaffyConfig::default(),
         }
     }