]>
git.proxmox.com Git - rustc.git/blob - vendor/serde_derive/src/lib.rs
1 // Copyright 2017 Serde Developers
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.
9 //! This crate provides Serde's two derive macros.
13 //! # extern crate serde_derive;
15 //! #[derive(Serialize, Deserialize)]
21 //! Please refer to [https://serde.rs/derive.html] for how to set this up.
23 //! [https://serde.rs/derive.html]: https://serde.rs/derive.html
25 #![doc(html_root_url = "https://docs.rs/serde_derive/1.0.75")]
26 #![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
27 // Whitelisted clippy lints
29 feature
= "cargo-clippy",
32 redundant_field_names
,
34 used_underscore_binding
,
35 cyclomatic_complexity
,
36 needless_pass_by_value
39 // Whitelisted clippy_pedantic lints
41 feature
= "cargo-clippy",
43 items_after_statements
,
52 cast_possible_truncation
,
56 // The `quote!` macro requires deep recursion.
57 #![recursion_limit = "512"]
64 extern crate proc_macro
;
65 extern crate proc_macro2
;
69 use proc_macro
::TokenStream
;
82 #[proc_macro_derive(Serialize, attributes(serde))]
83 pub fn derive_serialize(input
: TokenStream
) -> TokenStream
{
84 let input
: DeriveInput
= syn
::parse(input
).unwrap();
85 ser
::expand_derive_serialize(&input
)
86 .unwrap_or_else(compile_error
)
90 #[proc_macro_derive(Deserialize, attributes(serde))]
91 pub fn derive_deserialize(input
: TokenStream
) -> TokenStream
{
92 let input
: DeriveInput
= syn
::parse(input
).unwrap();
93 de
::expand_derive_deserialize(&input
)
94 .unwrap_or_else(compile_error
)
98 fn compile_error(message
: String
) -> proc_macro2
::TokenStream
{
100 compile_error
!(#message);