mod formats
- module formats
Module for handling the output formats supported.
Functions
- fn generate_decoration (ch : char , len : usize) -> String
Generate title decoration string for RST or fence for MD.
- Args:
- ch:
The character to use.
- len:
The length of the decoration required.
- Returns:
A string of length
lencomposed entirely ofch.
Traits
- trait MdContent
Trait for anything that can be converted to MD directive content.
This is implemented for all
IntoInterator<Item = String>, effectively allowingVec<String>to be converted to MD content lines.- fn get_md_text (self) -> Vec < String >
- trait MdDirective
Trait for directives that can be written as MD content
- fn get_md_text (self , fence_size : usize , max_visibility : & DirectiveVisibility) -> Vec < String >
Generate MD text with the given fence size.
Implementations must provide a vec of the lines of the content of the item and all its members.
- Args:
- fence_size:
The size of the fence for the directive. Use the
make_fencefunction to get the actual fence string.- max_visibility:
Include only items with visibility up to the defined level.
- Returns:
The MD text for the documentation of the item and its members.
- fn make_fence (fence_size : usize) -> String
Make a string for the fences for the directive.
- Args:
- fence_size:
The size of the fence, must be at least 3.
- Returns:
A string of colons of length
fence_size.- Panics:
If the
fence_sizeis less than 3.
- fn calc_fence_size (items : & [Directive]) -> usize
Calculate the fence size required for the item.
The
itemsare the members of the current item. So, for a struct, these will be the list of its fields, for an enum, the variants, for a module, the items defined in it, etc.The fence size for the item is 1 + the max fence size of all its members. If it has no members, the fence size is 3. So, the returned value is the minimum fence size required to properly document the item and its members in Markdown. Depending on the parent path of the item, the actual fence size used for documentation may be different, but at least the value returned by this function.
- Args:
- items:
Items which are members of the current item.
- Returns:
The minimum fence size required to document the item.
- fn make_md_header < O : MdOption > (directive : & str , name : & str , options : & [O] , fence : & str ,) -> Vec < String >
Make the MD directive header from the directive, name and options.
- Args:
- directive:
The MD directive to make the header for.
- name:
The name of the directive.
- options:
The directive options to add.
- fence:
The fence to use for the directive.
- Returns:
A Vec of the directive’s header lines.
- fn make_md_toctree (fence_size : usize , caption : & str , max_depth : Option < u8 > , dirname : Option < & str > , tree : & Vec < & str > ,) -> Vec < String >
- fn make_md_section (section : & str , fence_size : usize , items : Vec < Directive > , max_visibility : & DirectiveVisibility ,) -> Vec < String >
- fn fence_size (& self) -> usize
Return the fence size required for documenting the item.
The default implementation returns
3, which is the size required for any item that has no members and the minimum size required by Markdown.Implementations may use
calc_fence_sizeto override this.
- trait RstContent
Trait for anything that can be converted to RST directive content.
This is implemented for all
IntoInterator<Item = String>, effectively allowingVec<String>to be converted to RST content lines.- fn get_rst_text (self , indent : & str) -> Vec < String >
- trait RstDirective
Trait for directives that can be written as RST content
- const INDENT: & 'static str
- fn get_rst_text (self , level : usize , max_visibility : & DirectiveVisibility) -> Vec < String >
Generate RST text with the given level of indentation.
Implementations must provide a vec of the lines of the content of the item and all its members.
- Args:
- level:
The level of indentation for the content. Use the
make_indentandmake_content_indentfunctions to get the actual indentation string.- max_visibility:
Include only items with visibility up to the defined level.
- Returns:
The RST text for the documentation of the item and its members.
- fn make_indent (level : usize) -> String
Make a string for indenting the directive.
- Args:
- level:
The level of the indentation.
- Returns:
A string that is
Self::INDENTrepeatedleveltimes.
- fn make_content_indent (level : usize) -> String
Make a string for indenting the directive’s content and options
- Args:
- level:
The level of the indentation.
- Returns:
A string that is
Self::INDENTrepeatedlevel + 1times.
- fn make_rst_header < O : RstOption > (directive : & str , name : & str , options : & [O] , level : usize ,) -> Vec < String >
Make the RST directive header from the directive, name and options.
- Args:
- directive:
The RST directive to make the header for.
- name:
The name of the directive.
- options:
The directive options to add.
- level:
The indentation level of the directive.
- Returns:
A Vec of the directive’s header lines.
- fn make_rst_toctree (indent : & str , caption : & str , max_depth : Option < u8 > , dirname : Option < & str > , tree : & Vec < & str > ,) -> Vec < String >
- fn make_rst_section (section : & str , level : usize , items : Vec < Directive > , max_visibility : & DirectiveVisibility ,) -> Vec < String >
- trait RstOption
Trait for RST directive options
- fn get_rst_text (& self , indent : & str) -> String
Enums
Impls
- impl Format
- const MD_VALUES: [& 'static str ; 3]
- const RST_VALUES: [& 'static str ; 3]
- fn extension (& self) -> & 'static str
Returns the extension for the format
- fn make_title (& self , title : & str , as_code : bool) -> Vec < String >
Make a format specific document title using the provided title string.
- fn format_directive < T > (& self , directive : T , max_visibility : & DirectiveVisibility ,) -> Vec < String > where T : RstDirective + MdDirective ,
Get format specific content for the directive for the output file.
The function assumes that the directive is the top level directive of the output file and generates the content accordingly.
- Args:
- directive:
The directive to get the content for, typically a
CrateorModuledirective.
- Returns:
A vec of strings which are the lines of the document.
- fn format_content < T > (& self , content : T) -> Vec < String > where T : RstContent + MdContent ,
Get format specific content for the output file.
This function should not be used for content under a directive.
- Args:
- content:
The content for the file.
- Returns:
A vec of strings which are the lines of the document.
- impl FromStr for Format
- type Err
- fn from_str (value : & str) -> Result < Self , Self :: Err >
Parses the string into an enum value, or panics.
If the string is
md,.mdormarkdown, the function returnsMd. If the string isrst,.rstorrestructuredtext, the function returnsRst. Comparison is case-insensitive.- Args:
- value:
The value to parse.
- Returns:
The parsed enum value as the Ok value, or unit type as the Err.