-
-
Notifications
You must be signed in to change notification settings - Fork 791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Macros 1.1 #530
Macros 1.1 #530
Changes from all commits
d914fdf
3c45e5c
178edd1
54cee86
cdb0e6c
87a402a
88d845c
ac1128a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 <[email protected]>"] | ||
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" } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why pin to a particular serde_codegen? Shouldn't it be forward compatible? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same reason we pin There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess what I'm saying is: no it's not forward compatible 😈 |
||
|
||
[dev-dependencies] | ||
fnv = "1.0" | ||
serde = { version = "0.8.5", path = "../serde" } | ||
serde_test = { version = "0.8.5", path = "../serde_test" } |
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() | ||
} |
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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the confusing diff - this is just splitting
expand
intoexpand
andexpand_str
with common code insyntex_registry
.