diff --git a/app/gui/view/graph-editor/Cargo.toml b/app/gui/view/graph-editor/Cargo.toml index 760d8b24b9b..07fb743d9c0 100644 --- a/app/gui/view/graph-editor/Cargo.toml +++ b/app/gui/view/graph-editor/Cargo.toml @@ -15,7 +15,7 @@ bimap = { version = "0.4.0" } enso-config = { version = "0.1.0", path = "../../config" } enso-frp = { version = "0.1.0", path = "../../../../lib/rust/frp" } enso-logger = { path = "../../../../lib/rust/logger"} -enso-prelude = { path = "../../../../lib/rust/prelude"} +enso-prelude = { path = "../../../../lib/rust/prelude", features = ["serde"] } engine-protocol = { version = "0.1.0", path = "../../controller/engine-protocol" } enso-shapely = { path = "../../../../lib/rust/shapely"} enso-text = { version = "0.1.0", path = "../../../../lib/rust/text" } diff --git a/lib/rust/prelude/src/serde.rs b/lib/rust/prelude/src/serde.rs index 37290ec75f3..79174bc1a98 100644 --- a/lib/rust/prelude/src/serde.rs +++ b/lib/rust/prelude/src/serde.rs @@ -1,7 +1,7 @@ //! Module for utilities related to serialization/deserialization using the `serde` library. +#[cfg(feature = "serde_json")] use serde::Deserialize; -use serde::Deserializer; @@ -11,7 +11,7 @@ use serde::Deserializer; pub fn deserialize_or_default<'d, Ret, D>(d: D) -> Result where for<'e> Ret: Default + Deserialize<'e>, - D: Deserializer<'d>, { + D: serde::Deserializer<'d>, { // We first parse as generic JSON value. This is necessary to consume parser input. // If we just tried parsing the desired type directly and ignored error, we would end up with // `trailing characters` error in non-trivial cases. diff --git a/lib/rust/prelude/src/string.rs b/lib/rust/prelude/src/string.rs index a207f4e3820..fa96dc11a2a 100644 --- a/lib/rust/prelude/src/string.rs +++ b/lib/rust/prelude/src/string.rs @@ -217,12 +217,32 @@ impl PartialEq for String { // === Macros === /// Defines a newtype for `ImString`. +#[cfg(not(feature = "serde"))] #[macro_export] macro_rules! im_string_newtype { + ($($(#$meta:tt)* $name:ident),* $(,)?) => { + im_string_newtype_without_serde!{ $($(#$meta)* $name),* } + }; +} + +/// Defines a newtype for `ImString`. +#[cfg(feature = "serde")] +#[macro_export] +macro_rules! im_string_newtype { + ($($(#$meta:tt)* $name:ident),* $(,)?) => { + im_string_newtype_without_serde!{ $( + #[derive($crate::serde_reexports::Serialize,$crate::serde_reexports::Deserialize)] + $(#$meta)* $name + ),* } + }; +} + +#[macro_export] +macro_rules! im_string_newtype_without_serde { ($($(#$meta:tt)* $name:ident),* $(,)?) => {$( $(#$meta)* #[derive(Clone,CloneRef,Debug,Default,Eq,Hash,PartialEq)] - #[derive($crate::serde_reexports::Serialize,$crate::serde_reexports::Deserialize)] + pub struct $name { content : ImString }