使用自定义命令扩展 Cargo
Extending Cargo with Custom Commands
Cargo 的设计使得你可以在不修改它的情况下通过新的子命令来扩展它。如果你 $PATH 中的某个二进制文件名为 cargo-something,你可以像运行 Cargo 子命令一样通过运行 cargo something 来运行它。当你运行 cargo --list 时,这类自定义命令也会被列出。能够使用 cargo install 安装扩展,然后像内置 Cargo 工具一样运行它们,是 Cargo 设计中一个超级方便的优势!
Cargo is designed so that you can extend it with new subcommands without having
to modify it. If a binary in your $PATH is named cargo-something, you can
run it as if it were a Cargo subcommand by running cargo something. Custom
commands like this are also listed when you run cargo --list. Being able to
use cargo install to install extensions and then run them just like the
built-in Cargo tools is a super-convenient benefit of Cargo’s design!
总结
Summary
通过 Cargo 和 crates.io 分享代码是使 Rust 生态系统对许多不同任务都非常有用的原因之一。Rust 的标准库规模虽小且稳定,但 crate 易于分享、使用,并能在与语言不同的时间线上进行改进。不要羞于在 crates.io 上分享对你有用的代码;它很可能对其他人也有用!
Sharing code with Cargo and crates.io is part of what makes the Rust ecosystem useful for many different tasks. Rust’s standard library is small and stable, but crates are easy to share, use, and improve on a timeline different from that of the language. Don’t be shy about sharing code that’s useful to you on crates.io; it’s likely that it will be useful to someone else as well!