Skip to content

Commit

Permalink
Add a proc_macro component to serde_with
Browse files Browse the repository at this point in the history
A proc_macro is required to implement skip_serializing_null from
dtolnay/request-for-implementation#18

Expose the macro crate in serde_with

* Add a "macros"-feature to disable compiling proc_macros
* Add the feature to the testing matrix
  • Loading branch information
jonasbb committed Mar 31, 2019
1 parent 26d84b1 commit fb20c9f
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ before_script:
script:
- set -e
- |
for FEATURES_COMMAND in "--no-default-features" "" "--features=chrono" "--features=json" "--all-features"
for FEATURES_COMMAND in "--no-default-features" "" "--features=chrono" "--features=json" "--features=macros" "--all-features"
do
cargo build --verbose --all ${FEATURES_COMMAND}
# skip this step if clippy is not available, e.g., bad nightly
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added

* Add `skip_serializing_null` attribute, which adds `#[serde(skip_serializing_if = "Option::is_none")]` for each Option in a struct.
This is helpfull for APIs which have many optional fields.

## [1.2.0]

### Added
Expand Down
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[workspace]
members = [
"serde_with_macros",
]

[package]
name = "serde_with"
version = "1.2.0"
Expand Down Expand Up @@ -26,12 +31,15 @@ codecov = { repository = "jonasbb/serde_with", branch = "master", service = "git
maintenance = { status = "actively-developed" }

[features]
default = [ "macros" ]
json = [ "serde_json" ]
macros = [ "serde_with_macros" ]

[dependencies]
chrono = { version = "0.4.1", features = [ "serde" ], optional = true }
serde = "1.0.75"
serde_json = { version = "1.0.1", optional = true }
serde_with_macros = { path = "./serde_with_macros", version = "0.1.0", optional = true}

[dev-dependencies]
fnv = "1.0.6"
Expand Down
21 changes: 21 additions & 0 deletions serde_with_macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "serde_with_macros"
version = "0.1.0"
authors = ["jonasbb"]

description = "proc-macro library for serde_with"
documentation = "https://docs.rs/serde_with_macros/"
repository = "https://github.com/jonasbb/serde_with/serde_with_macros"
readme = "README.md"
keywords = ["serde", "utilities", "serialization", "deserialization"]
license = "MIT/Apache-2.0"

[lib]
proc-macro = true

[badges]
travis-ci = { repository = "jonasbb/serde_with", branch = "master" }
codecov = { repository = "jonasbb/serde_with", branch = "master", service = "github" }
maintenance = { status = "actively-developed" }

[dependencies]
1 change: 1 addition & 0 deletions serde_with_macros/LICENSE-APACHE
1 change: 1 addition & 0 deletions serde_with_macros/LICENSE-MIT
1 change: 1 addition & 0 deletions serde_with_macros/README.md
Empty file added serde_with_macros/src/lib.rs
Empty file.
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ extern crate chrono as chrono_crate;
pub extern crate serde;
#[cfg(feature = "json")]
extern crate serde_json;
#[cfg(feature = "macros")]
extern crate serde_with_macros;

#[cfg(feature = "chrono")]
pub mod chrono;
Expand All @@ -94,6 +96,11 @@ pub mod rust;
#[doc(hidden)]
pub mod with_prefix;

// Re-Export all proc_macros, as these should be seen as part of the serde_with crate
#[cfg(feature = "macros")]
#[doc(inline)]
pub use serde_with_macros::*;

/// Separator for string-based collection de/serialization
pub trait Separator {
/// Return the string delimiting two elements in the string-based collection
Expand Down

0 comments on commit fb20c9f

Please sign in to comment.