1 | pub use self::case_style::snakify; |
2 | pub use self::inner_variant_props::HasInnerVariantProperties; |
3 | pub use self::type_props::HasTypeProperties; |
4 | pub use self::variant_props::HasStrumVariantProperties; |
5 | |
6 | pub mod case_style; |
7 | pub mod inner_variant_props; |
8 | mod metadata; |
9 | pub mod type_props; |
10 | pub mod variant_props; |
11 | |
12 | use proc_macro2::Span; |
13 | use quote::ToTokens; |
14 | use syn::spanned::Spanned; |
15 | |
16 | pub fn missing_parse_err_attr_error() -> syn::Error { |
17 | syn::Error::new( |
18 | Span::call_site(), |
19 | message:"`parse_err_ty` and `parse_err_fn` attributes are both required." , |
20 | ) |
21 | } |
22 | |
23 | pub fn non_enum_error() -> syn::Error { |
24 | syn::Error::new(Span::call_site(), message:"This macro only supports enums." ) |
25 | } |
26 | |
27 | pub fn non_unit_variant_error() -> syn::Error { |
28 | syn::Error::new( |
29 | Span::call_site(), |
30 | message:"This macro only supports enums of strictly unit variants. Consider \ |
31 | message: using it in conjunction with [`EnumDiscriminants`]" , |
32 | ) |
33 | } |
34 | |
35 | pub fn non_single_field_variant_error(attr: &str) -> syn::Error { |
36 | syn::Error::new( |
37 | Span::call_site(), |
38 | message:format_args!( |
39 | "The [` {}`] attribute only supports enum variants with a single field" , |
40 | attr |
41 | ), |
42 | ) |
43 | } |
44 | |
45 | pub fn strum_discriminants_passthrough_error(span: &impl Spanned) -> syn::Error { |
46 | syn::Error::new( |
47 | span.span(), |
48 | message:"expected a pass-through attribute, e.g. #[strum_discriminants(serde(rename = \"var0 \"))]" , |
49 | ) |
50 | } |
51 | |
52 | pub fn occurrence_error<T: ToTokens>(fst: T, snd: T, attr: &str) -> syn::Error { |
53 | let mut e: Error = syn::Error::new_spanned( |
54 | tokens:snd, |
55 | message:format!("Found multiple occurrences of strum( {})" , attr), |
56 | ); |
57 | e.combine(another:syn::Error::new_spanned(tokens:fst, message:"first one here" )); |
58 | e |
59 | } |
60 | |