Crate sphinx-rustdocgen documentation

crate sphinx-rustdocgen

Library for the docextractor executable.

It consists of functions to extract content from the AST and to write the content to an RST or MD file. The crate is tested on itself, so all the documentation in the crate is in RST. The tests for Markdown are done on the dependencies.

Macros

macro push_module_files

Macro to push the module files to the files vec for processing

Args:
files:

The files list to push the files to.

parent:

The parent path of the module or crate’s file.

directive:

The directive for the module or crate.

Functions

fn check_and_create_output_dir (crate_name : & str , output_dir : & Path) -> PathBuf

Checks that the output directory ends with the crates name, and creates it if necessary.

Args:
crate_name:

The name of the crate.

output_dir:

The output path provided to check.

Returns:

A canonical form of the output directory for the crate’s docs.

Panics:

If the output directory cannot be created.

fn check_crate_src_dir (crate_name : & str , crate_src_dir : & Path) -> PathBuf

Checks that the crate’s source directory exists and returns a canonical form.

Note that this does not check that the crate name is the same as the crate’s directory name. This is intentional to allow renaming the crate for the documentation.

Args:
crate_name:

The name of the crate.

crate_src_dir:

The crate’s source directory as provided.

Returns:

A canonical form of the input, that ends with src (i.e. the directory under which main.rs and lib.rs exist).

Panics:

If the input path contains non UTF-8 characters, cannot be accessed or is not a directory.

fn find_mod_file (parent : & Path , module_directive : & ModuleDirective) -> PathBuf
fn get_doc_file_from_path (output_dir : & Path , rel_path : & Path , format : & Format) -> (String , File)

Get the document file from the relative path of the module.

Args:
output_dir:

The output directory for the crate’s docs.

rel_path:

The relative path of the module file within the crate

format:

The format for the output file.

Returns:

A tuple of the file name and File for writing the document content to. The file is opened for writing and truncated.

Panics:

If the file cannot be created or there are non unicode characters in the file path.

fn read_rs_file (path : & Path) -> syn :: File

Read a Rust source code file and generate its AST.

Args:
path:

The path to the file to read.

Returns:

The AST for the file generated by syn.

Panics:

If syn cannot parse the file.

fn traverse_crate (crate_name : & str , crate_src_dir : & Path , output_dir : & Path , format : Format , max_visibility : DirectiveVisibility ,)

Traverse the crate and extract the docstrings for the items.

Args:
crate_name:

The name of the crate.

crate_src_dir:

The directory with the crate source code.

output_dir:

The directory where to produce the generated documentation files.

format:

The format of the docstrings.

Enums

enum FileType

The different types of files that can be encountered.

Bin(String)

A file that compiles to a binary

Lib(String)

The crate’s library file.

Mod(String)

All other modules within the crate’s library.

Modules