rust - 是否有可以格式化导入的 Rust crate 或 Cargo 升级?

标签 rust

有没有办法优化和格式化范围内的所有 crate 导入,以清理导入部分?问题是进口商品变得拥挤和堆积。

之前:

use actix_web::web::{Data, Payload};
use actix_web::Error;
use actix_web::{
    error::{BlockingError, ErrorUnauthorized},
    web, HttpResponse,
};

之后:

use actix_web::{web::
                {Data, Payload},
                Error,
                error::{BlockingError, ErrorUnauthorized},
                web, HttpResponse,
};

最佳答案

实际上 rustfmt 可以做到这一点。在您的项目目录中创建一个 rustfmt.toml 配置文件并指定以下内容:

merge_imports = true

rustfmtmore configurable options如果你有兴趣。

关于rust - 是否有可以格式化导入的 Rust crate 或 Cargo 升级?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58405293/

相关文章:

rust - 可选择跳过使用 Serde 序列化字段?

rust - 为什么我需要在 “cover”中使用 `impl ForeignTrait<LocalType> for T` T [E0210]

rust - 在 HashMap 上实现一个使用带边界方法的特征

rust - 在 Substrate runtime crate 中定义的类型 Log 在哪里?

rust - 如何在 rust 中声明除生命周期之外的相同类型的泛型参数?

rust - 如何在 Rust 中连接静态切片?

rust - 为什么 slice::binary_search 返回不正确的结果?

rust - 从 PathBuf 获取绝对路径

rust - 当我没有对它进行任何更改时,是否可以避免重新编译它?

postgresql - 在RUST中将Postgresql时间戳转换为字符串