1mod derive_path_str;
2mod dynamic_spacing;
3
4use proc_macro::TokenStream;
5
6/// Derives the `path` method for an enum.
7///
8/// This macro generates a `path` method for each variant of the enum, which returns a string
9/// representation of the enum variant's path. The path is constructed using a prefix and
10/// optionally a suffix, which are specified using attributes.
11///
12/// # Attributes
13///
14/// - `#[path_str(prefix = "...")]`: Required. Specifies the prefix for all paths.
15/// - `#[path_str(suffix = "...")]`: Optional. Specifies a suffix for all paths.
16/// - `#[strum(serialize_all = "...")]`: Optional. Specifies the case conversion for variant names.
17///
18/// # Example
19///
20/// ```
21/// use strum::EnumString;
22/// use ui_macros::{path_str, DerivePathStr};
23///
24/// #[derive(EnumString, DerivePathStr)]
25/// #[path_str(prefix = "my_prefix", suffix = ".txt")]
26/// #[strum(serialize_all = "snake_case")]
27/// enum MyEnum {
28/// VariantOne,
29/// VariantTwo,
30/// }
31///
32/// // These assertions would work if we could instantiate the enum
33/// // assert_eq!(MyEnum::VariantOne.path(), "my_prefix/variant_one.txt");
34/// // assert_eq!(MyEnum::VariantTwo.path(), "my_prefix/variant_two.txt");
35/// ```
36///
37/// # Panics
38///
39/// This macro will panic if used on anything other than an enum.
40#[proc_macro_derive(DerivePathStr, attributes(path_str))]
41pub fn derive_path_str(input: TokenStream) -> TokenStream {
42 derive_path_str::derive_path_str(input)
43}
44
45/// A marker attribute for use with `DerivePathStr`.
46///
47/// This attribute is used to specify the prefix and suffix for the `path` method
48/// generated by `DerivePathStr`. It doesn't modify the input and is only used as a
49/// marker for the derive macro.
50#[proc_macro_attribute]
51pub fn path_str(_args: TokenStream, input: TokenStream) -> TokenStream {
52 // This attribute doesn't modify the input, it's just a marker
53 input
54}
55
56/// Generates the DynamicSpacing enum used for density-aware spacing in the UI.
57#[proc_macro]
58pub fn derive_dynamic_spacing(input: TokenStream) -> TokenStream {
59 dynamic_spacing::derive_spacing(input)
60}