| 1 | use proc_macro2::TokenStream; |
| 2 | use quote::quote; |
| 3 | |
| 4 | pub fn wrap_in_const(serde_path: Option<&syn::Path>, code: TokenStream) -> TokenStream { |
| 5 | let use_serde: TokenStream = match serde_path { |
| 6 | Some(path: &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 | |