Attribute Macro rename_item::rename

source ·
#[rename]
Expand description

Changes the name of the annotated item.

This macro changes the name of an item, which might make it difficult to refer to this item later. The renamed! macro can be used to obtain the new name of the item.

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 target case style can be omitted. In that case the default case style for the item’s type will be used: snake_case for functions and modules, SHOUTY_SNAKE_CASE for constants and statics, and UpperCamelCase for types and traits.

Examples

#[rename(name = "my-constant")]
const foo: u32 = 1;
assert_eq!(MY_CONSTANT, 1);

#[rename(name(my, "constant"), case = "upper_camel", prefix = "_")]
const foo: u32 = 2;
assert_eq!(_MyConstant, 2);