This directory provides a complete script in offline-only mode:
- Select a local cloned repository directory.
- Recursively scan all Rust files (
.rs) under that directory. - Analyze public unsafe items in four categories:
function:pub unsafe fnmethod:pub unsafe fninsideimpltrait:pub unsafe traittrait_method:unsafe fndefined inside apub unsafe trait(nopubrequired; API name format isTraitName::MethodName)
- Extract full documentation comments for each item as
full_doc(description, examples, safety section, etc.). - Extract the
# Safetysection only as a separate fieldsafety_doc. - Generate a frontend report page suitable for GitHub Pages (HTML table + confirmation button).
- Provide Type multi-select filtering (with per-type counts) and fuzzy search for Module Path and API Name.
- Support JSON export from the webpage (exports currently filtered rows).
unsafe_doc_generator.py: main script- Default outputs after running:
site/index.htmlsite/unsafe_items.json
Run in this directory (offline scan):
python3 unsafe_doc_generator.py \
--local-dir "/path/to/local/repo/subdir" \
--remote-repo-url "https://github.com/<owner>/<repo>" \
--remote-ref "<branch-or-tag>" \
--remote-path-prefix "<optional/path/prefix>" \
--output-dir siteExample:
python3 unsafe_doc_generator.py \
--local-dir "/home/chenyl/projects/linux/rust/kernel" \
--remote-repo-url "https://github.com/Rust-for-Linux/linux" \
--remote-ref "rust-next" \
--remote-path-prefix "rust/kernel" \
--output-dir linux_kernel--local-dir: local scan directory (required).--remote-repo-url+--remote-ref: used to generate clickable API links to remote repository lines (.../blob/<ref>/<path>#L<line>).--remote-path-prefix: optional manual remote path prefix (e.g.rust/kernel). If omitted, the script tries to infer it from local git repository root.--output-dir: output directory.
Fields shown in index.html:
- index
- module path
- API name (clickable when remote repo URL is provided)
- type (
function | method | trait | trait_method) - full doc
- safety doc (only
# Safetysection) Confirmedbutton (state stored in browserlocalStorage; default isNot Confirmed, clicked state isConfirmed ✓)
Fields in unsafe_items.json:
indexmodule_pathapi_nameitem_typefull_docsafety_docsource_pathsource_lineapi_link
Note: source_url is not included.
- Top
Source URLdisplays remote repository URL when--remote-repo-urlis provided. - Multi-select Type filter with per-type counts.
- Fuzzy search for Module Path and API Name.
- One-click JSON export for currently filtered rows.
To publish the generated page on GitHub, enable GitHub Pages and publish the contents of your output directory (for example, /docs on your default branch).