如何删除 Cargo.toml 中未使用的依赖项?

How do I remove unused dependencies in Cargo.toml?

提问人:z11i 提问时间:5/2/2022 更新时间:7/17/2023 访问量:9775

问:

如何找出 Cargo.toml 中未使用的依赖项?如何自动删除它们?

锈货物

评论

4赞 BallpointBen 5/2/2022
似乎 github.com/est31/cargo-udeps 和/或 github.com/Bromeon/cargo-machete 是你最好的选择
0赞 after-ephemera 8/25/2022
看来货砍刀现在已经不见了。
0赞 Enoch Chejieh 10/23/2022
你可以用这个货砍刀箱代替。

答:

19赞 z11i 5/2/2022 #1

一种选择是使用 cargo-udeps

您可以通过命令安装它:

cargo install cargo-udeps --locked

然后,若要在生产目标中查找未使用的依赖项,请执行以下操作:

cargo +nightly udeps

要查找未使用的开发依赖项,请执行以下操作:

cargo +nightly udeps --all-targets