serde_derive/
lib.rs

1//! This crate provides Serde's two derive macros.
2//!
3//! ```edition2021
4//! # use serde_derive::{Deserialize, Serialize};
5//! #
6//! #[derive(Serialize, Deserialize)]
7//! # struct S;
8//! #
9//! # fn main() {}
10//! ```
11//!
12//! Please refer to [https://serde.rs/derive.html] for how to set this up.
13//!
14//! [https://serde.rs/derive.html]: https://serde.rs/derive.html
15
16#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.210")]
17#![cfg_attr(not(check_cfg), allow(unexpected_cfgs))]
18// Ignored clippy lints
19#![allow(
20    // clippy false positive: https://github.com/rust-lang/rust-clippy/issues/7054
21    clippy::branches_sharing_code,
22    clippy::cognitive_complexity,
23    // clippy bug: https://github.com/rust-lang/rust-clippy/issues/7575
24    clippy::collapsible_match,
25    clippy::derive_partial_eq_without_eq,
26    clippy::enum_variant_names,
27    // clippy bug: https://github.com/rust-lang/rust-clippy/issues/6797
28    clippy::manual_map,
29    clippy::match_like_matches_macro,
30    clippy::needless_pass_by_value,
31    clippy::too_many_arguments,
32    clippy::trivially_copy_pass_by_ref,
33    clippy::used_underscore_binding,
34    clippy::wildcard_in_or_patterns,
35    // clippy bug: https://github.com/rust-lang/rust-clippy/issues/5704
36    clippy::unnested_or_patterns,
37)]
38// Ignored clippy_pedantic lints
39#![allow(
40    clippy::cast_possible_truncation,
41    clippy::checked_conversions,
42    clippy::doc_markdown,
43    clippy::enum_glob_use,
44    clippy::indexing_slicing,
45    clippy::items_after_statements,
46    clippy::let_underscore_untyped,
47    clippy::manual_assert,
48    clippy::map_err_ignore,
49    clippy::match_same_arms,
50    // clippy bug: https://github.com/rust-lang/rust-clippy/issues/6984
51    clippy::match_wildcard_for_single_variants,
52    clippy::module_name_repetitions,
53    clippy::must_use_candidate,
54    clippy::similar_names,
55    clippy::single_match_else,
56    clippy::struct_excessive_bools,
57    clippy::too_many_lines,
58    clippy::unseparated_literal_suffix,
59    clippy::unused_self,
60    clippy::use_self,
61    clippy::wildcard_imports
62)]
63#![cfg_attr(all(test, exhaustive), feature(non_exhaustive_omitted_patterns_lint))]
64
65extern crate proc_macro2;
66extern crate quote;
67extern crate syn;
68
69extern crate proc_macro;
70
71mod internals;
72
73use proc_macro::TokenStream;
74use syn::parse_macro_input;
75use syn::DeriveInput;
76
77#[macro_use]
78mod bound;
79#[macro_use]
80mod fragment;
81
82mod de;
83mod dummy;
84mod pretend;
85mod ser;
86mod this;
87
88#[proc_macro_derive(Serialize, attributes(serde))]
89pub fn derive_serialize(input: TokenStream) -> TokenStream {
90    let mut input = parse_macro_input!(input as DeriveInput);
91    ser::expand_derive_serialize(&mut input)
92        .unwrap_or_else(syn::Error::into_compile_error)
93        .into()
94}
95
96#[proc_macro_derive(Deserialize, attributes(serde))]
97pub fn derive_deserialize(input: TokenStream) -> TokenStream {
98    let mut input = parse_macro_input!(input as DeriveInput);
99    de::expand_derive_deserialize(&mut input)
100        .unwrap_or_else(syn::Error::into_compile_error)
101        .into()
102}