]>
Commit | Line | Data |
---|---|---|
3b2f2976 XL |
1 | // Copyright 2017 Serde Developers |
2 | // | |
3 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
4 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
5 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
6 | // option. This file may not be copied, modified, or distributed | |
7 | // except according to those terms. | |
8 | ||
9 | //! This crate provides Serde's two derive macros. | |
10 | //! | |
11 | //! ```rust,ignore | |
12 | //! #[derive(Serialize, Deserialize)] | |
13 | //! ``` | |
14 | //! | |
15 | //! Please refer to [https://serde.rs/derive.html] for how to set this up. | |
16 | //! | |
17 | //! [https://serde.rs/derive.html]: https://serde.rs/derive.html | |
18 | ||
ea8adc8c | 19 | #![doc(html_root_url = "https://docs.rs/serde_derive/1.0.15")] |
3b2f2976 XL |
20 | |
21 | #![cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))] | |
22 | #![cfg_attr(feature = "cargo-clippy", allow(used_underscore_binding))] | |
23 | ||
24 | // The `quote!` macro requires deep recursion. | |
25 | #![recursion_limit = "192"] | |
26 | ||
27 | extern crate syn; | |
28 | #[macro_use] | |
29 | extern crate quote; | |
30 | ||
31 | extern crate serde_derive_internals as internals; | |
32 | ||
33 | extern crate proc_macro; | |
34 | use proc_macro::TokenStream; | |
35 | ||
36 | #[macro_use] | |
37 | mod bound; | |
38 | #[macro_use] | |
39 | mod fragment; | |
40 | ||
41 | mod ser; | |
42 | mod de; | |
43 | ||
44 | #[proc_macro_derive(Serialize, attributes(serde))] | |
45 | pub fn derive_serialize(input: TokenStream) -> TokenStream { | |
46 | let input = syn::parse_derive_input(&input.to_string()).unwrap(); | |
47 | match ser::expand_derive_serialize(&input) { | |
48 | Ok(expanded) => expanded.parse().unwrap(), | |
49 | Err(msg) => panic!(msg), | |
50 | } | |
51 | } | |
52 | ||
53 | #[proc_macro_derive(Deserialize, attributes(serde))] | |
54 | pub fn derive_deserialize(input: TokenStream) -> TokenStream { | |
55 | let input = syn::parse_derive_input(&input.to_string()).unwrap(); | |
56 | match de::expand_derive_deserialize(&input) { | |
57 | Ok(expanded) => expanded.parse().unwrap(), | |
58 | Err(msg) => panic!(msg), | |
59 | } | |
60 | } |