Skip to content

Commit

Permalink
Add serde support of HList data structures via a feature-gate (lloydm…
Browse files Browse the repository at this point in the history
…eta#65)

Inspired by recent progress in https://github.com/Sgeo/hlist
  • Loading branch information
lloydmeta authored Sep 9, 2017
1 parent 66c0151 commit f553118
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
16 changes: 12 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
[package]
name = "frunk"
version = "0.1.31"
version = "0.1.32"
authors = ["Lloyd <[email protected]>"]
description = "Frunk provides developers with a number of functional programming tools like HList, Coproduct, Generic, LabelledGeneric, Validated, Monoid, Semigroup and friends."
license = "MIT"
documentation = "https://docs.rs/frunk"
repository = "https://github.com/lloydmeta/frunk"
keywords = ["Frunk", "HList", "Generic", "Validated", "Monoid"]
readme = "README.md"

[badges]
travis-ci = { repository = "lloydmeta/frunk" }
Expand All @@ -16,12 +17,19 @@ time = "0.1.36"

[dependencies.frunk_core]
path = "core"
version = "0.0.18"
version = "0.0.19"

[dependencies.frunk_derives]
path = "derives"
version = "0.0.19"
version = "0.0.20"

[dev-dependencies.frunk_laws]
path = "laws"
version = "0.0.9"
version = "0.0.10"

[dependencies]
serde = { version = "^1.0", optional = true, default-features = false }
serde_derive = { version = "^1.0", optional = true, default-features = false }

[features]
with-serde = ["serde", "serde_derive"]
11 changes: 9 additions & 2 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "frunk_core"
version = "0.0.18"
version = "0.0.19"
authors = ["Lloyd <[email protected]>"]
description = "Frunk core provides developers with HList and Generic"
license = "MIT"
Expand All @@ -11,6 +11,13 @@ keywords = ["Frunk", "HList", "Generic", "LabelledGeneric"]
[badges]
travis-ci = { repository = "lloydmeta/frunk" }

[dependencies]
serde = { version = "^1.0", optional = true, default-features = false }
serde_derive = { version = "^1.0", optional = true, default-features = false }

[features]
with-serde = ["serde", "serde_derive"]

[dev-dependencies.frunk_derives]
path = "../derives"
version = "0.0.19"
version = "0.0.20"
2 changes: 2 additions & 0 deletions core/src/hlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ pub trait HList: Sized {
/// assert_eq!(h, 1);
/// ```
#[derive(PartialEq, Debug, Eq, Clone, Copy, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "with_serde", derive(Serialize, Deserialize))]
pub struct HNil;

impl HList for HNil {
Expand All @@ -152,6 +153,7 @@ impl AsRef<HNil> for HNil {
/// Represents the most basic non-empty HList. Its value is held in `head`
/// while its tail is another HList.
#[derive(PartialEq, Debug, Eq, Clone, Copy, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "with_serde", derive(Serialize, Deserialize))]
pub struct HCons<H, T> {
pub head: H,
pub tail: T,
Expand Down
4 changes: 4 additions & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,7 @@
pub mod hlist;
pub mod generic;
pub mod labelled;

#[cfg(feature = "with_serde")]
#[macro_use]
extern crate serde_derive;
4 changes: 2 additions & 2 deletions derives/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "frunk_derives"
version = "0.0.19"
version = "0.0.20"
authors = ["Lloyd <[email protected]>"]
description = "frunk_derives contains the custom derivations for certain traits in Frunk."
license = "MIT"
Expand All @@ -20,4 +20,4 @@ quote = "0.3.15"

[dependencies.frunk_core]
path = "../core"
version = "0.0.18"
version = "0.0.19"
4 changes: 2 additions & 2 deletions laws/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "frunk_laws"
version = "0.0.9"
version = "0.0.10"
authors = ["Lloyd <[email protected]>"]
description = "frunk_laws contains laws for algebras declared in Frunk."
license = "MIT"
Expand All @@ -13,7 +13,7 @@ travis-ci = { repository = "lloydmeta/frunk" }

[dependencies.frunk]
path = ".."
version = "0.1.31"
version = "0.1.32"

[dependencies]
quickcheck = "0.4.1"

0 comments on commit f553118

Please sign in to comment.