# Crate `rustdown` Module Structure
```
rustdown
├── manifest_dir (3 struct: CrateManifest, GitInfo, ManifestDir)
├── markdown (4 fn: format_generation_header, format_usages, get_relative_source_path, rustdoc_to_markdown, 1 struct: MarkdownOptions)
├── parser (20 struct: ConstantRef, FunctionRef, MacroRef, ModuleRef, ParsedAssociatedConstant, ParsedAssociatedType, ParsedCrate, ParsedField, ParsedFunction, ParsedGenerics, ParsedMethod, ParsedModule, ParsedParameter, ParsedSignature, ParsedTrait, ParsedType, ParsedVariant, SourceLocation, TraitRef, TypeRef, 5 enum: GenericParam, MacroKind, ParsedVisibility, TypeKind, VariantKind)
├── printer (1 fn: print_module_tree)
├── rust_analyzer (4 fn: find_identifier_position, find_item_usages, initialize_ra_session, shutdown_ra_session, 2 struct: ReferenceInfo, RustAnalyzerSession, 2 const: RA_SESSION, USAGE_CACHE)
└── rustdoc (1 fn: generate_rustdoc_json)
```
# Root `rustdown` Module
Rustdown - Convert Rust documentation JSON to Markdown
This crate provides functionality to convert rustdoc's JSON output into
readable Markdown documentation optimized for LLM consumption.
# Module `crate::manifest_dir`
## [`struct ManifestDir`](src/manifest_dir.rs#L9)
```
struct ManifestDir {
manifest_dir: std::path::PathBuf,
members: Vec<CrateManifest>,
is_workspace: bool,
}
```
### [`ManifestDir::detect`](src/manifest_dir.rs#L38)
`fn detect(start_path: &Path) -> Result<Self>`
### [`ManifestDir::get_git_info`](src/manifest_dir.rs#L132)
`fn get_git_info(self: &Self) -> Result<Option<GitInfo>>`
## [`struct CrateManifest`](src/manifest_dir.rs#L16)
```
struct CrateManifest {
name: String,
manifest_path: std::path::PathBuf,
relative_path: std::path::PathBuf,
}
```
## [`struct GitInfo`](src/manifest_dir.rs#L210)
```
struct GitInfo {
commit_hash: String,
commit_timestamp: String,
is_dirty: bool,
}
```
# Module `crate::markdown`
## [`struct MarkdownOptions`](src/markdown.rs#L12)
Options for markdown generation
```
struct MarkdownOptions {
compact: bool,
manifest_path: Option<std::path::PathBuf>,
max_tree_items: Option<usize>,
output_path: Option<std::path::PathBuf>,
show_signatures: bool,
show_tree: bool,
show_usages: bool,
workspace_relative_path: Option<std::path::PathBuf>,
}
```
## [`fn get_relative_source_path`](src/markdown.rs#L50)
Get the source file path relative to the crate root
When rustdoc generates JSON for workspace members, paths are relative to the workspace root.
This function makes paths relative to where the rustdown.md file will be placed.
In compact mode, returns only the filename instead of the full path.
# Examples
- File in same crate `crates/utils`: `crates/utils/src/file.rs` → `src/file.rs`
- File in other crate from `crates/utils`: `crates/cli/src/main.rs` → `../cli/src/main.rs`
- Standalone crate: `src/main.rs` → `src/main.rs` (unchanged)
- Compact mode: `src/file/operations.rs` → `operations.rs`
`fn get_relative_source_path(source_path: &std::path::Path, options: &MarkdownOptions) -> std::path::PathBuf`
## [`fn rustdoc_to_markdown`](src/markdown.rs#L101)
Convert rustdoc JSON data to Markdown format
`fn rustdoc_to_markdown(rustdoc: rustdoc_types::Crate, options: MarkdownOptions) -> String`
## [`fn format_generation_header`](src/markdown.rs#L170)
`fn format_generation_header(git_info: Option<&manifest_dir::GitInfo>) -> String`
## [`fn format_usages`](src/markdown.rs#L808)
Format usage references for markdown output
`fn format_usages(references: &[rust_analyzer::ReferenceInfo], options: &MarkdownOptions) -> String`
# Module `crate::parser`
## [`struct ParsedCrate`](src/parser.rs#L11)
Represents a parsed crate with all its modules and items organized hierarchically
```
struct ParsedCrate {
/// The name of the crate
name: String,
/// The version of the crate if specified
version: Option<String>,
/// The root module containing all items
root_module: ParsedModule,
/// All modules indexed by their ID for quick lookup
modules_by_id: std::collections::HashMap<rustdoc_types::Id, ParsedModule>,
/// All types (structs, enums, unions) indexed by ID
types_by_id: std::collections::HashMap<rustdoc_types::Id, ParsedType>,
/// All functions indexed by ID
functions_by_id: std::collections::HashMap<rustdoc_types::Id, ParsedFunction>,
/// All traits indexed by ID
traits_by_id: std::collections::HashMap<rustdoc_types::Id, ParsedTrait>,
}
```
### [`ParsedCrate::is_inline_module`](src/parser.rs#L295)
Check if a module is defined inline within another file
`fn is_inline_module(span: &Option<rustdoc_types::Span>, module_name: &str) -> bool`
### [`ParsedCrate::from_rustdoc`](src/parser.rs#L324)
Parse a rustdoc JSON crate into our rich data structure
`fn from_rustdoc(rustdoc: &Crate) -> Self`
### [`ParsedCrate::parse_module_items`](src/parser.rs#L369)
Parse items within a module
`fn parse_module_items(self: &mut Self, rustdoc: &Crate, item_ids: &[Id], parent_module: &mut ParsedModule, parent_path: &str)`
### [`ParsedCrate::parse_struct`](src/parser.rs#L536)
`fn parse_struct(self: &Self, item: &Item, struct_: &rustdoc_types::Struct, rustdoc: &Crate, path: &str) -> ParsedType`
### [`ParsedCrate::parse_enum`](src/parser.rs#L631)
`fn parse_enum(self: &Self, item: &Item, enum_: &rustdoc_types::Enum, rustdoc: &Crate, path: &str) -> ParsedType`
### [`ParsedCrate::parse_union`](src/parser.rs#L742)
`fn parse_union(self: &Self, item: &Item, union_: &rustdoc_types::Union, rustdoc: &Crate, path: &str) -> ParsedType`
### [`ParsedCrate::parse_function`](src/parser.rs#L782)
`fn parse_function(self: &Self, item: &Item, func: &rustdoc_types::Function, rustdoc: &Crate, path: &str) -> ParsedFunction`
### [`ParsedCrate::parse_trait`](src/parser.rs#L801)
`fn parse_trait(self: &Self, item: &Item, trait_: &rustdoc_types::Trait, rustdoc: &Crate, path: &str) -> ParsedTrait`
## [`struct ParsedModule`](src/parser.rs#L30)
Represents a module with its items
```
struct ParsedModule {
/// Module ID
id: rustdoc_types::Id,
/// Module name (None for root module)
name: Option<String>,
/// Full path to this module (e.g., "crate::foo::bar")
path: String,
/// Documentation
docs: Option<String>,
/// Source location
source: Option<SourceLocation>,
/// Whether this module is defined inline within another file
is_inline: bool,
/// Child modules
submodules: Vec<ModuleRef>,
/// Types defined in this module (structs, enums, unions, type aliases)
types: Vec<TypeRef>,
/// Functions defined in this module
functions: Vec<FunctionRef>,
/// Traits defined in this module
traits: Vec<TraitRef>,
/// Constants and statics
constants: Vec<ConstantRef>,
/// Macros
macros: Vec<MacroRef>,
}
```
## [`struct ModuleRef`](src/parser.rs#L59)
Reference to a module
```
struct ModuleRef {
id: rustdoc_types::Id,
name: String,
path: String,
is_inline: bool,
}
```
## [`struct TypeRef`](src/parser.rs#L68)
Reference to a type
```
struct TypeRef {
id: rustdoc_types::Id,
name: String,
kind: TypeKind,
}
```
## [`struct FunctionRef`](src/parser.rs#L76)
Reference to a function
```
struct FunctionRef {
id: rustdoc_types::Id,
name: String,
is_async: bool,
is_unsafe: bool,
is_const: bool,
}
```
## [`struct TraitRef`](src/parser.rs#L86)
Reference to a trait
```
struct TraitRef {
id: rustdoc_types::Id,
name: String,
is_unsafe: bool,
is_auto: bool,
}
```
## [`struct ConstantRef`](src/parser.rs#L95)
Reference to a constant or static
```
struct ConstantRef {
id: rustdoc_types::Id,
name: String,
is_static: bool,
}
```
## [`struct MacroRef`](src/parser.rs#L103)
Reference to a macro
```
struct MacroRef {
id: rustdoc_types::Id,
name: String,
kind: MacroKind,
}
```
## [`struct ParsedType`](src/parser.rs#L111)
Represents a parsed type (struct, enum, union, or type alias)
```
struct ParsedType {
id: rustdoc_types::Id,
name: String,
path: String,
kind: TypeKind,
docs: Option<String>,
source: Option<SourceLocation>,
visibility: ParsedVisibility,
generics: Option<ParsedGenerics>,
/// Methods and associated functions
methods: Vec<ParsedMethod>,
/// Implemented traits
implemented_traits: Vec<String>,
/// For enums: variants
variants: Vec<ParsedVariant>,
/// For structs: fields
fields: Vec<ParsedField>,
}
```
## [`enum TypeKind`](src/parser.rs#L132)
Kind of type
```
enum TypeKind {
Struct,
Enum,
Union,
TypeAlias,
}
```
## [`struct ParsedFunction`](src/parser.rs#L141)
Represents a parsed function
```
struct ParsedFunction {
id: rustdoc_types::Id,
name: String,
path: String,
docs: Option<String>,
source: Option<SourceLocation>,
visibility: ParsedVisibility,
signature: ParsedSignature,
generics: Option<ParsedGenerics>,
}
```
## [`struct ParsedSignature`](src/parser.rs#L154)
Function signature details
```
struct ParsedSignature {
is_async: bool,
is_unsafe: bool,
is_const: bool,
is_extern: bool,
abi: Option<String>,
parameters: Vec<ParsedParameter>,
return_type: Option<String>,
}
```
### [`ParsedSignature::from_function`](src/parser.rs#L958)
`fn from_function(func: &rustdoc_types::Function, rustdoc: &Crate) -> Self`
## [`struct ParsedParameter`](src/parser.rs#L166)
Function parameter
```
struct ParsedParameter {
name: String,
type_str: String,
}
```
## [`struct ParsedTrait`](src/parser.rs#L173)
Represents a parsed trait
```
struct ParsedTrait {
id: rustdoc_types::Id,
name: String,
path: String,
docs: Option<String>,
source: Option<SourceLocation>,
visibility: ParsedVisibility,
is_unsafe: bool,
is_auto: bool,
generics: Option<ParsedGenerics>,
/// Required methods
required_methods: Vec<ParsedMethod>,
/// Provided methods (with default implementation)
provided_methods: Vec<ParsedMethod>,
/// Associated types
associated_types: Vec<ParsedAssociatedType>,
/// Associated constants
associated_constants: Vec<ParsedAssociatedConstant>,
/// Types that implement this trait
implementors: Vec<String>,
}
```
## [`struct ParsedMethod`](src/parser.rs#L197)
Method or associated function
```
struct ParsedMethod {
id: rustdoc_types::Id,
name: String,
docs: Option<String>,
signature: ParsedSignature,
is_default: bool,
}
```
## [`struct ParsedAssociatedType`](src/parser.rs#L207)
Associated type in a trait
```
struct ParsedAssociatedType {
id: rustdoc_types::Id,
name: String,
docs: Option<String>,
bounds: Vec<String>,
default: Option<String>,
}
```
## [`struct ParsedAssociatedConstant`](src/parser.rs#L217)
Associated constant in a trait
```
struct ParsedAssociatedConstant {
id: rustdoc_types::Id,
name: String,
docs: Option<String>,
type_str: String,
default: Option<String>,
}
```
## [`struct ParsedVariant`](src/parser.rs#L227)
Enum variant
```
struct ParsedVariant {
id: rustdoc_types::Id,
name: String,
docs: Option<String>,
kind: VariantKind,
discriminant: Option<String>,
}
```
## [`enum VariantKind`](src/parser.rs#L237)
Variant kind
```
enum VariantKind {
Plain,
Tuple(Vec<String>),
Struct(Vec<ParsedField>),
}
```
## [`struct ParsedField`](src/parser.rs#L245)
Struct or variant field
```
struct ParsedField {
id: Option<rustdoc_types::Id>,
name: Option<String>,
type_str: String,
docs: Option<String>,
visibility: ParsedVisibility,
}
```
## [`enum ParsedVisibility`](src/parser.rs#L255)
Parsed visibility
```
enum ParsedVisibility {
Public,
Private,
Crate,
Restricted(String),
}
```
### [`ParsedVisibility::from_visibility`](src/parser.rs#L907)
`fn from_visibility(vis: &Visibility) -> Self`
## [`struct ParsedGenerics`](src/parser.rs#L264)
Generic parameters
```
struct ParsedGenerics {
params: Vec<GenericParam>,
where_predicates: Vec<String>,
}
```
### [`ParsedGenerics::from_generics`](src/parser.rs#L918)
`fn from_generics(generics: &rustdoc_types::Generics, _context: T) -> Option<Self>`
## [`enum GenericParam`](src/parser.rs#L271)
Generic parameter
```
enum GenericParam {
Type {
name: String,
bounds: Vec<String>,
},
Lifetime {
name: String,
bounds: Vec<String>,
},
Const {
name: String,
type_: String,
},
}
```
## [`struct SourceLocation`](src/parser.rs#L279)
Source location
```
struct SourceLocation {
file: String,
line: usize,
column: usize,
}
```
### [`SourceLocation::from_span`](src/parser.rs#L897)
`fn from_span(span: &Option<rustdoc_types::Span>) -> Option<Self>`
## [`enum MacroKind`](src/parser.rs#L287)
Macro kind
```
enum MacroKind {
Declarative,
ProcMacro,
Derive,
Attribute,
}
```
# Module `crate::printer`
## [`fn print_module_tree`](src/printer.rs#L63)
`fn print_module_tree(module: &crate::parser::ParsedModule, crate_data: &crate::ParsedCrate, rustdoc: &rustdoc_types::Crate, indent: usize, crate_root: Option<&std::path::Path>)`
# Module `crate::rust_analyzer`
## [`struct ReferenceInfo`](src/rust_analyzer.rs#L11)
```
struct ReferenceInfo {
file_path: String,
line: u32,
column: u32,
}
```
## [`struct RustAnalyzerSession`](src/rust_analyzer.rs#L17)
```
struct RustAnalyzerSession {
root_path: std::path::PathBuf,
}
```
### [`RustAnalyzerSession::new`](src/rust_analyzer.rs#L25)
`fn new(crate_path: &Path) -> Result<Self, Box<dyn std::error::Error>>`
### [`RustAnalyzerSession::open_document`](src/rust_analyzer.rs#L192)
`fn open_document(self: &mut Self, file_path: &Path) -> Result<(), Box<dyn std::error::Error>>`
### [`RustAnalyzerSession::wait_for_indexing`](src/rust_analyzer.rs#L214)
`fn wait_for_indexing(self: &mut Self) -> Result<(), Box<dyn std::error::Error>>`
### [`RustAnalyzerSession::wait_for_indexing_with_verification`](src/rust_analyzer.rs#L218)
`fn wait_for_indexing_with_verification(self: &mut Self, crate_path: &Path, test_items: &[(Id, String, PathBuf, u32, ItemEnum)]) -> Result<(), Box<dyn std::error::Error>>`
### [`RustAnalyzerSession::wait_for_indexing_with_modules`](src/rust_analyzer.rs#L373)
`fn wait_for_indexing_with_modules(self: &mut Self, _module_names: &[String]) -> Result<(), Box<dyn std::error::Error>>`
### [`RustAnalyzerSession::find_references`](src/rust_analyzer.rs#L587)
`fn find_references(self: &mut Self, file_path: &Path, line: u32, column: u32) -> Result<Vec<ReferenceInfo>, Box<dyn std::error::Error>>`
### [`RustAnalyzerSession::shutdown`](src/rust_analyzer.rs#L653)
`fn shutdown(self: Self) -> Result<(), Box<dyn std::error::Error>>`
## [`fn find_identifier_position`](src/rust_analyzer.rs#L673)
`fn find_identifier_position(crate_path: &std::path::Path, file_path: &std::path::Path, line: u32, item_name: &str, item_kind: &rustdoc_types::ItemEnum) -> (u32, u32)`
## [`fn initialize_ra_session`](src/rust_analyzer.rs#L745)
Initialize rust-analyzer session for finding usages with ParsedCrate
`fn initialize_ra_session(crate_path: &std::path::Path, rustdoc: &rustdoc_types::Crate, workspace_relative_path: Option<&std::path::PathBuf>) -> Result<(), Box<dyn std::error::Error>>`
## [`fn shutdown_ra_session`](src/rust_analyzer.rs#L851)
Shutdown the rust-analyzer session
`fn shutdown_ra_session() -> Result<(), Box<dyn std::error::Error>>`
## [`fn find_item_usages`](src/rust_analyzer.rs#L861)
Find all usages of an item
`fn find_item_usages(item: &rustdoc_types::Item, crate_path: &std::path::Path, _rustdoc: &rustdoc_types::Crate) -> Vec<ReferenceInfo>`
## [`const RA_SESSION`](src/rust_analyzer.rs#L738)
## [`const USAGE_CACHE`](src/rust_analyzer.rs#L738)
# Module `crate::rustdoc`
## [`fn generate_rustdoc_json`](src/rustdoc.rs#L5)
`fn generate_rustdoc_json(manifest_path: Option<&std::path::Path>, target_dir: Option<&std::path::Path>, document_private_items: bool, features: &[String], all_features: bool) -> Result<String>`