#[document_type_parameters]Expand description
Generates documentation for type parameters.
This macro analyzes the item’s signature (function, struct, enum, impl block, etc.) and generates a documentation comment list based on the provided descriptions.
When used within a module annotated with #[document_module],
it benefits from automatic Self resolution and is applied as part of the module-level
documentation pass.
§Syntax
ⓘ
#[document_type_parameters(
"Description for first parameter",
("OverriddenName", "Description for second parameter"),
...
)]
pub fn function_name<Generics>(params) -> ReturnType { ... }It can also be used on other items like impl blocks:
ⓘ
#[document_type_parameters("Description for T")]
impl<T> MyType<T> { ... }§Parameters
Descriptions: A comma-separated list. Each entry can be either a string literal or a tuple of two string literals(Name, Description).
§Generates
A list of documentation comments, one for each generic parameter, prepended to the function definition.
§Examples
ⓘ
// Invocation
#[document_type_parameters(
"The type of the elements.",
("E", "The error type.")
)]
pub fn map<T, ERR>(...) { ... }
// Expanded code
/// * `T`: The type of the elements.
/// * `E`: The error type.
pub fn map<T, ERR>(...) { ... }§Constraints
- The number of arguments must exactly match the number of generic parameters (including lifetimes, types, and const generics) in the function signature.