Skip to main content

icon_named

Macro icon_named 

Source
icon_named!() { /* proc-macro */ }
Expand description

Generate a custom icon enum and its IconNamed impl by scanning a directory of SVG files.

Accepts an enum name, a path, and optionally a list of additional derive traits. Each .svg file becomes an enum variant using PascalCase conversion.

The path may be either:

  • A literal path (the common case), resolved relative to the calling crate’s CARGO_MANIFEST_DIR. Use this when the icons live inside your own package.
  • An env-var reference of the form "$NAME", where NAME names a build-time environment variable whose value is the absolute path to the icons directory. Use this when the icons live in another crate and the path is plumbed through cargo’s links / DEP_<X>_<KEY> propagation mechanism. The default IconName enum in gpui-component uses this pattern to consume icons from gpui-kit-assets without a sibling-crate reference, which would otherwise break cargo vendor and cargo publish.

§Example

// Literal path (relative to the calling crate's CARGO_MANIFEST_DIR)
icon_named!(IconName, "icons");

// Env-var reference (resolved at macro expansion time)
icon_named!(IconName, "$GPUI_KIT_DEFAULT_ICONS_DIR");

// With custom derives
icon_named!(IconName, "icons", [Debug, Copy, PartialEq, Eq]);