2 个版本
0.1.2 | 2020 年 7 月 12 日 |
---|---|
0.1.1 | 2020 年 7 月 11 日 |
#1 in #roc
33KB
645 代码行
roc — 非凡的 Rust 命令行文档
go doc
风格,通过 Rust 文档搜索 rust 库。
roc
是基于 rustdoc 生成的 HTML 文档的,所以如果您想查看除了标准库之外的内容,您需要在 roc 之前运行 cargo doc
。roc 主要旨在提供一个快速接口来查找文档摘要:大部分顶级细节都会显示,但如果您需要阅读完整文档,请通过查询传递 -o
标志。这将使用您的默认网页浏览器打开本地文档页面。
注意事项
- 这是一个正在进行中的项目!有多个功能需要实现(部分匹配搜索、bash/zsh 完成脚本、按签名搜索等),以及几个已知的问题,主要是在输出格式方面。如果您有目前尚未涵盖的使用案例或添加功能的想法,请在该 GitHub 仓库中提出问题或 PR,如果您愿意自己实现这些功能。
roc
假定您正在使用 rustup 并且您已下载了 stdlib 文档。如果没有,您将无法搜索std
中的任何内容的文档。roc
需要您在找到之前构建任何依赖库的文档。最简单的工作流程是在您更新Cargo.toml
时运行cargo doc
,以确保您的本地生成的文档是最新的。
示例用法
# show summary comment for the Eq trait from stdlib
$ roc std::cmp::Eq
Trait for equality comparisons which are equivalence relations.
This means, that in addition to a == b and a != b being strict inverses, the equality must
be (for all a, b and c)
# generate the documentation for roc itself
$ cd roc && cargo doc
# list out all of the known crates that we can find from this directory
$ roc .
:: known crates
atty bit_set bit_vec bitflags cfg_if
clap clap_derive colored debug_unreachable futf
heck html5ever implementors indexmap lazy_static
libc log mac markup5ever markup5ever_rcdom
os_str_bytes phf phf_shared precomputed_hash proc_macro2
proc_macro_error proc_macro_error_attr quote rocdoc select
serde siphasher std string_cache strsim
syn syn_mid tendril term_size termcolor
textwrap time unicode_segmentation unicode_width unicode_xid
utf8 vec_map xml5ever
# show top level summary details for the roc crate
$ roc rocdoc
roc - command line doucmentation that rocks
roc is an attempt at bringing godoc style quick docs searching to the command
line for rust. It doesn\'t generate any documentation itself, instead it relies
entirely on the local HTML output created by running cargo doc in the root of
your crate. You will need to have rust installed via rustup and have the std lib
docs downloaded in order to look at std lib.
:: modules
locate Locate the generated docs that we have available within the current workspace
parse Parse the contents of rustdoc generated HTML files
pprint Formatted output and pretty printing
# show specific information about the Locator struct
$ roc rocdoc::locate::Locator
pub struct Locator { /* fields omitted */ }
A Locator handles mapping a user query string from the command line to a file
location on disk. It also provides information about what kind of documentation
file it has found so that the appropriate parsing of the file contents can be
carried out.
pub fn new(query: String) -> Self
pub fn target_file_path(&self) -> Option<String>
pub fn determine_tagged_path(&self) -> Option<TaggedPath>
当前标志
-l, --list list out modules under the current path
-o, --open open the selected doc page in the browser (local copy)
本地文件系统文档位置
std::* -> $(rustc --print sysroot)/share/doc/rust/html/std
* -> $(dirname Cargo.toml)/target/doc
依赖
~4–11MB
~114K SLoC