Macro rename_item::renamed

source ·
renamed!() { /* proc-macro */ }
Expand description

Expands to the name of an item.

This macro expands to the name specified by the macro arguments. To apply this name to an item, use the rename macro.

The name is given by a mix of string literals and identifiers, which are concatenated and adjusted to a given case style. Fixed prefix and suffix strings can also be provided, and will not be adjusted to the case style. For further information on how names are generated, refer to the module-level documentation.

The prefix and suffix strings can be used to extend the generated name beyond a single identifier. In this way, arbitrary tokens can be inserted before or after the generated name. This is useful for surrounding the generated name with additional path components (e.g. Self::) or expressions (e.g. 1+).

Examples

assert_eq!(renamed!(case = "snake", name = "foo-bar"), foo_bar);

assert_eq!(
    renamed!(case = "lower_camel", name(foo, "bar"), suffix = "1"),
    fooBar1
);

assert_eq!(
    renamed!(case = "snake", name = "foo-bar", prefix = "1+"),
    1 + foo_bar
);

The case style cannot be inferred from the item’s type and must always be specified. The following code fails to compile:

renamed!(name = "foo")