1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
// Copyright 2020 Oxide Computer Company //! `serde::Deserializer` implementation for `proc_macro2::TokenStream`. This //! is intended for proc_macro builders who want rich configuration in their //! custom attributes. //! //! If you'd like the consumers of your macro use it like this: //! //! ```ignore //! #[my_macro { //! settings = { //! reticulate_splines = true, //! normalizing_power = false, //! }, //! disaster = "pandemic", //! }] //! ``` //! //! Your macro will start like this: //! //! ```ignore //! #[proc_macro_attribute] //! pub fn my_macro( //! attr: proc_macro::TokenStream, //! item: proc_macro::TokenStream, //! ) -> proc_macro::TokenStream { //! ... //! ``` //! //! Use `serde_tokenstream` to deserialize `attr` into a structure with the //! `Deserialize` trait (typically via a `derive` macro): //! //! ``` //! # use proc_macro2::TokenStream; //! # use serde_tokenstream::from_tokenstream; //! # use serde::Deserialize; //! # #[derive(Deserialize)] //! # struct Config; //! # pub fn my_macro( //! # attr: proc_macro2::TokenStream, //! # item: proc_macro2::TokenStream, //! # ) -> proc_macro2::TokenStream { //! let config = match from_tokenstream::<Config>(&TokenStream::from(attr)) { //! Ok(c) => c, //! Err(err) => return err.to_compile_error().into(), //! }; //! # item //! # } //! ``` mod serde_tokenstream; pub use crate::serde_tokenstream::from_tokenstream; pub use crate::serde_tokenstream::Error; pub use crate::serde_tokenstream::Result;