Syner - A simple, fast and safe way to parse attributes from syn
Syner is a simple, fast and safe way to parse attributes from syn. It is designed to be used with the syn crate.
Definition of your attributes is done using a procedural macro. This allows you to define your attributes in a type safe way.
You create a struct that represents your attribute and then use the #[derive(Syner)] macro to generate the parsing code.
Example
This will parse the following attribute:
You can parse the attribute using the parse_attrs function.
It takes an iterator of syn::Attribute and returns a Result with the parsed attribute.
let attrs = parse_attrs?;
Supported types
Syner supports the following types:
String- Parses the value as a stringbool- Parses the value as a booleani8,i16,i32,i64,i128,isize- Parses the value as a signed integeru8,u16,u32,u64,u128,usize- Parses the value as an unsigned integerf32,f64- Parses the value as a floatT- Parses the value as<name>(T)ifTis a struct that implementsSynerOption<T>- Parses the value asTif it is presentVec<T>- Parses the value as<name>(T...)
Annotating a field with #[syner(default)] will make it optional and use the default value if it is not present.
The name of the field is used as the name of the attribute except if the field is of type Vec<T>,
in which case the name of the struct (lowercase) is used.
For the top level attribute the lowercase name of the struct is used.
License
This project is licensed under the MIT License - see the LICENSE file for details