[−][src]Crate serde_tokenstream
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:
ⓘThis example is not tested
#[my_macro {
settings = {
reticulate_splines = true,
normalizing_power = false,
},
disaster = "pandemic",
}]
Your macro will start like this:
ⓘThis example is not tested
#[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):
let config = match from_tokenstream::<Config>(&TokenStream::from(attr)) { Ok(c) => c, Err(err) => return err.to_compile_error().into(), };
Functions
from_tokenstream | Deserialize an instance of type T from a TokenStream. |
Type Definitions
Error | Alias for |
Result | Alias for a Result with the error type serde_tokenstream::Error. |