Support precompiled deserialize_in_place

This commit is contained in:
David Tolnay
2023-07-19 11:53:45 -07:00
parent e2d8589976
commit 2027088741
6 changed files with 23 additions and 1 deletions
+7
View File
@@ -1,5 +1,7 @@
use proc_macro2::{Literal, Span, TokenStream};
use quote::ToTokens;
#[cfg(precompiled)]
use std::sync::atomic::Ordering;
use syn::punctuated::Punctuated;
use syn::spanned::Spanned;
use syn::{self, Ident, Index, Member};
@@ -304,6 +306,11 @@ fn deserialize_body(cont: &Container, params: &Parameters) -> Fragment {
#[cfg(feature = "deserialize_in_place")]
fn deserialize_in_place_body(cont: &Container, params: &Parameters) -> Option<Stmts> {
#[cfg(precompiled)]
if !crate::DESERIALIZE_IN_PLACE.load(Ordering::Relaxed) {
return None;
}
// Only remote derives have getters, and we do not generate
// deserialize_in_place for remote derives.
assert!(!params.has_getter);
+5
View File
@@ -78,6 +78,8 @@ extern crate proc_macro2 as proc_macro;
mod internals;
use proc_macro::TokenStream;
#[cfg(precompiled)]
use std::sync::atomic::AtomicBool;
use syn::DeriveInput;
#[macro_use]
@@ -102,6 +104,9 @@ macro_rules! parse_macro_input {
};
}
#[cfg(precompiled)]
pub static DESERIALIZE_IN_PLACE: AtomicBool = AtomicBool::new(false);
#[cfg_attr(not(precompiled), proc_macro_derive(Serialize, attributes(serde)))]
pub fn derive_serialize(input: TokenStream) -> TokenStream {
let mut input = parse_macro_input!(input as DeriveInput);