Rust specific roles

The extension provides the following roles, which can be referenced as :rust:<role_name>:. For all roles, the target is the double colon (::) delimited full Rust path to the item, similar to the path used when importing the item. This syntax is slightly extended to accomodate linking to trait impl blocks and fields within a struct. More details are described below.

For all roles, adding a ~ before the path will display only the final portion of the path as the link text. So, :rust:fn:`~crate::module::func` will display only func as the link text.

crate

:rust:crate:`<crate_name>` links to the crate’s documentation, within lib.rs.

enum

:rust:enum:`<enum_path>` links to an enum’s documentation. Specific variant’s within the enum can be referenced using the struct role.

fn, function

:rust:fn:`<fn_path>` links to a function’s documentation.

To a reference a function, use the full path to the impl block where the function is defined, followed by the function’s name. See the impl block documentation below for details.

Note that the path <trait_path>::<fn> references the function within the trait, whereas <struct_path>::<trait>::<fn> references the implementation of the function for the struct.

impl

:rust:impl:`<impl_path>` links to an impl block, either of the struct, or for a trait for a struct.

When referencing an impl block for a struct or an enum, use the full path to the impl block within the crate. So, if the impl Foo block is in a different module from the struct itself, the path must reference the module of the impl block. Items within the impl block like functions and variables are then nested under this path.

When referencing a trait impl block, the last two components of the path are <type>::<trait>. So, a block impl Display for Foo is referenced as crate::module::Foo::Display.

macro

:rust:macro:`<macro_path>` inks to a macro’s documentation.

module

:rust:module:`<module_path>` inks to the module’s documentation. The module path here is the Rust path of the module, not its file’s path.

struct

:rust:struct:`<struct_path>` links to a struct or an enum variant’s documentation. For an enum variant, use :rust:struct:`<enum_path>::<variant>` as the target.

Specific fields within the struct or variant can be referenced using the variable role.

trait

:rust:trait:`<trait_path>` links to a trait’s documentation. Items defined within the trait are nested under the trait’s path.

type

:rust:type:`<type_path>` links to a type’s documentation.

var, variable

:rust:var:`<variable_path>` links to a static or const variable, or to a field within a struct or enum variant.

For fields of a struct, the path is <struct_path>::<field_name>, For tuple structs, the field’s index should be used instead of the name. For an enum variant’s fields, the path is <enum_path>::<variant>::<field_name>, with field index instead of name for tuple variants.