x-i18n: generated_at: “2026-03-01T14:29:34Z” model: gemini-3-flash-preview provider: google-gemini-cli source_hash: 1a18d238852672a56de0b521226c4a6ef21946f0a3d6bec7f0ffb11794a4232e source_path: ch14-05-extending-cargo.md workflow: 16
使用自定义命令扩展 Cargo (Extending Cargo with Custom Commands)
Extending Cargo with Custom Commands
Cargo 的设计允许你使用新的子命令来扩展它,而无需修改 Cargo 本身。如果你的 $PATH 中有一个名为 cargo-something 的二进制文件,你可以通过运行 cargo something 来将其作为 Cargo 子命令运行。运行 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)
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!