tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5544Rust 88Markdown 11TOML 91926 Definitions

Fix serde feature with Units trait

Signed-off-by: Nico Burns <nico@nicoburns.com>

dff2beccf08bad5ea2c726f3b0b53b02ab2a68af · by Nico Burns · (1 year ago) · parent 7bbb03eb9 · browse the tree at this commit

Semantic delta · 2

src/style/mod.rs

  • signature changed trait Units pub

tests/serde.rs

2 files · +7 −2

diff --git a/src/style/mod.rs b/src/style/mod.rs
index 4be7baf89..b0ac5dc84 100644
--- a/src/style/mod.rs
+++ b/src/style/mod.rs
@@ -72,7 +72,12 @@ impl<T> Calc for T where T: Clone + Debug + 'static {}
 pub trait Units {
     /// Trait that represents a cheaply clonable string. If you're unsure what to use here
     /// consider `Arc<str>` or `string_cache::Atom`.
+    #[cfg(not(feature = "serde"))]
     type Str: CheapCloneStr;
+    /// Trait that represents a cheaply clonable string. If you're unsure what to use here
+    /// consider `Arc<str>` or `string_cache::Atom`.
+    #[cfg(feature = "serde")]
+    type Str: CheapCloneStr + serde::Serialize + for<'a> serde::Deserialize<'a>;
 
     /// Type representing a calc expression.
     /// If you're not using Calc then you can just use `()`
diff --git a/tests/serde.rs b/tests/serde.rs
index 0ddce2ba0..f2f9ecf7a 100644
--- a/tests/serde.rs
+++ b/tests/serde.rs
@@ -2,11 +2,11 @@
 #[cfg(feature = "serde")]
 mod serde {
     use serde_json::{self, Value};
-    use taffy::style::Style;
+    use taffy::{DefaultUnits, Style};
 
     #[test]
     fn serde_can_serialize() {
-        let style: Style<String> = Style::DEFAULT;
+        let style: Style<DefaultUnits> = Style::DEFAULT;
         let _ = serde_json::to_string(&style).unwrap();
     }