1use proc_macro2::TokenStream;
2use quote::quote;
3
4pub fn wrap_in_const(serde_path: Option<&syn::Path>, code: TokenStream) -> TokenStream {
5 let use_serde = match serde_path {
6 Some(path) => quote! {
7 use #path as _serde;
8 },
9 None => quote! {
10 #[allow(unused_extern_crates, clippy::useless_attribute)]
11 extern crate serde as _serde;
12 },
13 };
14
15 quote! {
16 #[doc(hidden)]
17 #[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
18 const _: () = {
19 #use_serde
20 #code
21 };
22 }
23}
24