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