如何删除货物中未使用的依赖项?
我如何找出未使用的货物中的依赖性?如何自动删除它们?
How do I find out the dependencies in Cargo.toml that are unused? How can I remove them automatically?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
货物 - udeps
需要夜间编译器,这可能引入潜在的不稳定性或兼容性问题。我建议使用 machete 。它可以与稳定的生锈编译器一起使用,并消除了潜在的夜间建造风险。它提供了一种快速便捷的方式来识别潜在的未使用依赖性。同样,可以将其配置为忽略特定的依赖性或提供更详细的信息。
安装砍刀:
在项目中查找未使用的依赖项:
修复未使用的依赖性:
cargo-udeps
requires the nightly compiler, which might introduce potential instability or compatibility issues.I recommend to use machete. It works with the stable Rust compiler and eliminates the risk of potentially unstable nightly builds. It offers a fast and convenient way to identify potential unused dependencies. Also, it can be configured to ignore specific dependencies or provide more detailed information.
Install machete:
Find unused dependencies in the project:
To fix unused dependencies:
cargo-shear
可以很好地使用,可以与稳定的工具链。安装:
检查是否有未使用的依赖项
可以修复(删除)未使用的依赖性:
cargo-shear
does this very nicely and can be used with the stable toolchain.Install:
Check if there are any unused dependencies
To fix (remove) an unused dependency:
截至
2024年9月,此答案需要每晚运行。如果您不想夜间构建,请参考Michael Hall或Mujeeb Kalwar的答案。
一种选择是使用 cargo-udeps 。
您可以通过命令安装它:
然后,要在生产目标中找到未使用的依赖项:
找到未使用的dev依赖项:
Update for 2024
As of Sep 2024, this answer requires nightly to run. If you don't want nightly builds, refer to Michael Hall's or Mujeeb Kalwar's answer instead.
One option is to use cargo-udeps.
You can install it via command:
Then, to find unused dependencies in production target:
To find unused dev dependencies: