-
-
Notifications
You must be signed in to change notification settings - Fork 777
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #530 from serde-rs/derive
Macros 1.1
- Loading branch information
Showing
4 changed files
with
103 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[package] | ||
name = "serde_derive" | ||
version = "0.8.5" | ||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"] | ||
license = "MIT/Apache-2.0" | ||
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]" | ||
homepage = "https://serde.rs" | ||
repository = "https://github.com/serde-rs/serde" | ||
documentation = "https://serde.rs/codegen.html" | ||
keywords = ["serde", "serialization"] | ||
include = ["Cargo.toml", "src/**/*.rs"] | ||
|
||
[lib] | ||
name = "serde_derive" | ||
rustc-macro = true | ||
|
||
[dependencies] | ||
serde_codegen = { version = "=0.8.5", path = "../serde_codegen" } | ||
|
||
[dev-dependencies] | ||
fnv = "1.0" | ||
serde = { version = "0.8.5", path = "../serde" } | ||
serde_test = { version = "0.8.5", path = "../serde_test" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#![feature(rustc_macro, rustc_macro_lib)] | ||
#![cfg(not(test))] | ||
|
||
extern crate rustc_macro; | ||
extern crate serde_codegen; | ||
|
||
use rustc_macro::TokenStream; | ||
|
||
#[rustc_macro_derive(Serialize)] | ||
pub fn derive_serialize(input: TokenStream) -> TokenStream { | ||
let item = format!("#[derive(Serialize)]\n{}", input); | ||
let expanded = serde_codegen::expand_str(&item).unwrap(); | ||
expanded.parse().unwrap() | ||
} | ||
|
||
#[rustc_macro_derive(Deserialize)] | ||
pub fn derive_deserialize(input: TokenStream) -> TokenStream { | ||
let item = format!("#[derive(Deserialize)]\n{}", input); | ||
let expanded = serde_codegen::expand_str(&item).unwrap(); | ||
expanded.parse().unwrap() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#![feature(test, rustc_macro, rustc_attrs)] | ||
|
||
#[macro_use] | ||
extern crate serde_derive; | ||
|
||
extern crate test; | ||
|
||
include!("../../testing/tests/test.rs.in"); |