mod directives

module directives

Module for the various Sphinx directives for the Rust domain.

The module primarily provides the Directive, which implements the various directives using directive specific structs. The enum and all directive specific structs implement both RstContent and MdContent traits. It also provides the DirectiveOption enum, which implements the various options of the directive.

The output of the directives is parsed by the sphinxcontrib_rust.directives.RustDirective within the Python extension.

Modules

Re-exports

Types

type ItemSections

Named type for the output of order_items.

Macros

macro push_sorted

Macro to sort and push items within a vec.

Functions

fn extract_doc_from_attrs(attrs: &Vec<Attribute>) -> Vec<String>

Extract the docstring from the attrs of an item.

Args:
attrs:

syn::attr::Attribute vec.

Returns:

A vec of strings, where each string is a line of a documentation comment. If there are no documentation comments, an empty vec is returned.

fn order_items(items: Vec<Directive>) -> ItemSections

Order the items for documentation

The items are ordered using the following rules:

  1. If the item is a module without content, it is removed and a link to the module is added to the toctree. If there are no such module, the toctree isn’t added.

  2. Each directive is then separated by type and ordered alphabetically except for impl directives.

  3. All impl blocks associated with a struct or enum are ordered after it, starting with the associated impl block, followed by trait impl blocks in alphabetical order.

It uses the push_sorted!() macro.

Returns:

A vec of section names with their directives.

Enums

enum Directive

The Sphinx directives that are implemented by the Rust domain.

Crate(CrateDirective)
Enum(EnumDirective)
Executable(ExecutableDirective)
Function(FunctionDirective)
Impl(ImplDirective)
Macro(MacroDirective)
Module(ModuleDirective)
Struct(StructDirective)
Trait(TraitDirective)
Type(TypeDirective)
Use(UseDirective)
Variable(VariableDirective)

Implementations

impl Directive

Functions

fn add_content<I: IntoIterator<Item = String>>(&mut self, content: I)

Add the content to the directive.

The content is appended to any existing content.

fn change_parent(&mut self, new_parent: &str)

Change the parent of the directive.

fn directive_visibility(&self) -> &DirectiveVisibility

Get the visibility of the directive.

fn from_extern_item(parent_path: &str, item: &ForeignItem) -> Option<Directive>

Create the appropriate directive from the provided syn::ForeignItem

Args:
parent_path:

The path of the module which defines the items.

item:

The foreign item to parse into a directive.

Returns:

An option a Directive variant.

fn from_extern_items<'a, T: Iterator<Item = &'a ForeignItem>>(parent_path: &str, items: T) -> Vec<Directive>

Create the appropriate directives from the provided syn::ForeignItem iterator.

Args:
parent_path:

The path of the trait which defines the items.

items:

The foreign items to parse into a directive.

Returns:

An vec of Directive variants.

fn from_impl_item(parent_path: &str, item: &ImplItem, inherited_visibility: &Option<&Visibility>) -> Option<Directive>

Create the appropriate directive from the provided syn::ImplItem

Args:
parent_path:

The path of the impl block which defines the item.

item:

The impl item to parse into a directive.

Returns:

An option a Directive variant.

fn from_impl_items<'a, T: Iterator<Item = &'a ImplItem>>(parent_path: &str, items: T, inherited_visibility: &Option<&Visibility>) -> Vec<Directive>

Create the appropriate directives from the provided syn::ImplItem iterator.

Args:
parent_path:

The path of the impl block which defines the items.

items:

The impl items to parse into a directive.

Returns:

An vec of Directive variants.

fn from_item(parent_path: &str, item: &Item, inherited_visibility: &Option<&Visibility>) -> Option<Directive>

Create the appropriate directive from the provided syn::Item

Args:
parent_path:

The parent path of the item.

item:

The item to parse into a directive.

Returns:

An option a Directive variant.

fn from_trait_item(parent_path: &str, item: &TraitItem, inherited_visibility: &Option<&Visibility>) -> Option<Directive>

Create the appropriate directive from the provided syn::TraitItem

Args:
parent_path:

The path of the trait which defines the items.

item:

The trait item to parse into a directive.

Returns:

An option a Directive variant.

fn from_trait_items<'a, T: Iterator<Item = &'a TraitItem>>(parent_path: &str, items: T, inherited_visibility: &Option<&Visibility>) -> Vec<Directive>

Create the appropriate directives from the provided syn::TraitItem iterator.

Args:
parent_path:

The path of the module which defines the items.

items:

The trait items to parse into a directive.

Returns:

An vec of Directive variants.

fn name(&self) -> &str

Traits implemented

impl RstDirective for Directive

Functions

fn get_rst_text(self, level: usize, max_visibility: &DirectiveVisibility) -> Vec<String>
impl MdDirective for Directive

Functions

fn fence_size(&self) -> usize
fn get_md_text(self, fence_size: usize, max_visibility: &DirectiveVisibility) -> Vec<String>

Structs and Unions

struct FileDirectives
modules: Vec<ModuleDirective>

The directives for the modules defined in the file.

impls: Vec<ImplDirective>

The directives for the impls defined in the file.

uses: Vec<UseDirective>

The directives for the use statements in the file.

items: Vec<Directive>

The directives for all other items in the file. This will never contain a module, impl or use directive.

Implementations

impl FileDirectives

Functions

fn claim_impls(&mut self, parent_name: &str, impls: Vec<ImplDirective>) -> Vec<ImplDirective>
fn from_ast_items(runtime_configuration: &RuntimeConfiguration, ast_items: &Vec<Item>, module_parent: &SourceCodeFile) -> Self

Create new file directives from the AST of a file.

Args:
ast_items:

A list of items parsed by syn.

module_parent:

The parent source code file to find modules under.