Skip to main content

doc_type_params

Attribute Macro doc_type_params 

Source
#[doc_type_params]
Expand description

Generates documentation for a function’s type parameters.

This macro analyzes the function signature and generates a documentation comment list based on the provided descriptions.

§Syntax

#[doc_type_params(
    "Description for first parameter",
    ("OverriddenName", "Description for second parameter"),
    ...
)]
pub fn function_name<Generics>(params) -> ReturnType { ... }

§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
#[doc_type_params(
    "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.