简体   繁体   English

是否有可以格式化导入的 Rust 板条箱或货物升级?

[英]Is there a Rust crate or Cargo upgrade that can format imports?

Is there a way to optimize and format all crate imports in scope, to clean up the imports sections?有没有办法优化和格式化 scope 中的所有板条箱导入,以清理导入部分? The problem is that the imports get crowded and stack up.问题是进口变得拥挤和堆积。

Before:前:

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

After:后:

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

Actually rustfmt can do this.实际上rustfmt可以做到这一点。 Create a rustfmt.toml configuration file in your project directory and specify the following:在您的项目目录中创建一个rustfmt.toml配置文件并指定以下内容:

merge_imports = true

The rustfmt has more configurable options if you are interested.如果您有兴趣, rustfmt更多可配置的选项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM