From a64e21ee6ee03897efdcd3334ddae49f62cd9dc1 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sat, 9 Jul 2022 21:08:11 +0100 Subject: [PATCH] group imports --- auth/casbin/src/main.rs | 4 ++-- auth/redis-session/src/main.rs | 3 ++- auth/simple-auth-server/src/email_service.rs | 5 ++--- auth/simple-auth-server/src/errors.rs | 3 ++- auth/simple-auth-server/src/models.rs | 3 ++- auth/simple-auth-server/src/utils.rs | 3 ++- basics/hello-world/src/main.rs | 3 ++- basics/nested-routing/src/bin/main.rs | 1 - basics/nested-routing/src/handlers/products.rs | 5 +++-- data-factory/src/main.rs | 1 - databases/mongodb/src/main.rs | 3 +-- databases/postgres/src/main.rs | 9 ++++++--- databases/sqlite/src/db.rs | 3 ++- forms/form/src/main.rs | 6 +++--- forms/multipart-s3/src/utils/s3.rs | 6 +++--- forms/multipart-s3/src/utils/upload.rs | 7 ++++--- graphql/juniper-advanced/src/schemas/root.rs | 7 ++++--- json/json/src/main.rs | 5 ++--- rustfmt.toml | 1 + shutdown-server/src/main.rs | 3 ++- templating/handlebars/src/main.rs | 17 ++++++++++------- templating/tera/src/main.rs | 15 +++++++++------ websockets/chat-tcp/src/server.rs | 3 ++- 23 files changed, 66 insertions(+), 50 deletions(-) diff --git a/auth/casbin/src/main.rs b/auth/casbin/src/main.rs index ff2cf908..47a5aff2 100644 --- a/auth/casbin/src/main.rs +++ b/auth/casbin/src/main.rs @@ -1,8 +1,8 @@ -use casbin::{CoreApi, DefaultModel, Enforcer, FileAdapter, RbacApi}; use std::io; -use tokio::sync::RwLock; use actix_web::{middleware, web, App, HttpRequest, HttpResponse, HttpServer}; +use casbin::{CoreApi, DefaultModel, Enforcer, FileAdapter, RbacApi}; +use tokio::sync::RwLock; /// simple handle async fn success(enforcer: web::Data>, req: HttpRequest) -> HttpResponse { diff --git a/auth/redis-session/src/main.rs b/auth/redis-session/src/main.rs index 07b144d7..6efeac26 100644 --- a/auth/redis-session/src/main.rs +++ b/auth/redis-session/src/main.rs @@ -100,7 +100,6 @@ async fn main() -> std::io::Result<()> { #[cfg(test)] mod test { - use super::*; use actix_web::{ middleware, web::{get, post, resource}, @@ -108,6 +107,8 @@ mod test { }; use serde_json::json; + use super::*; + #[actix_web::test] async fn test_workflow() { let private_key = actix_web::cookie::Key::generate(); diff --git a/auth/simple-auth-server/src/email_service.rs b/auth/simple-auth-server/src/email_service.rs index bcd1db77..ffaca525 100644 --- a/auth/simple-auth-server/src/email_service.rs +++ b/auth/simple-auth-server/src/email_service.rs @@ -1,10 +1,9 @@ -// email_service.rs -use crate::errors::ServiceError; -use crate::models::Invitation; use sparkpost::transmission::{ EmailAddress, Message, Options, Recipient, Transmission, TransmissionResponse, }; +use crate::{errors::ServiceError, models::Invitation}; + lazy_static::lazy_static! { static ref API_KEY: String = std::env::var("SPARKPOST_API_KEY").expect("SPARKPOST_API_KEY must be set"); } diff --git a/auth/simple-auth-server/src/errors.rs b/auth/simple-auth-server/src/errors.rs index 9b7019d2..9ac44dea 100644 --- a/auth/simple-auth-server/src/errors.rs +++ b/auth/simple-auth-server/src/errors.rs @@ -1,7 +1,8 @@ +use std::convert::From; + use actix_web::{error::ResponseError, HttpResponse}; use derive_more::Display; use diesel::result::{DatabaseErrorKind, Error as DBError}; -use std::convert::From; use uuid::Error as ParseError; #[derive(Debug, Display)] diff --git a/auth/simple-auth-server/src/models.rs b/auth/simple-auth-server/src/models.rs index 6510b574..073c3d9b 100644 --- a/auth/simple-auth-server/src/models.rs +++ b/auth/simple-auth-server/src/models.rs @@ -1,7 +1,8 @@ -use super::schema::*; use diesel::{r2d2::ConnectionManager, PgConnection}; use serde::{Deserialize, Serialize}; +use super::schema::*; + // type alias to use in multiple places pub type Pool = r2d2::Pool>; diff --git a/auth/simple-auth-server/src/utils.rs b/auth/simple-auth-server/src/utils.rs index 2f7483a4..f2856814 100644 --- a/auth/simple-auth-server/src/utils.rs +++ b/auth/simple-auth-server/src/utils.rs @@ -1,6 +1,7 @@ -use crate::errors::ServiceError; use argon2::{self, Config}; +use crate::errors::ServiceError; + lazy_static::lazy_static! { pub static ref SECRET_KEY: String = std::env::var("SECRET_KEY").unwrap_or_else(|_| "0123".repeat(8)); } diff --git a/basics/hello-world/src/main.rs b/basics/hello-world/src/main.rs index d76dc5ac..50960f0a 100644 --- a/basics/hello-world/src/main.rs +++ b/basics/hello-world/src/main.rs @@ -24,11 +24,12 @@ async fn main() -> std::io::Result<()> { #[cfg(test)] mod tests { - use super::*; use actix_web::body::to_bytes; use actix_web::dev::Service; use actix_web::{http, test, web, App, Error}; + use super::*; + #[actix_web::test] async fn test_index() -> Result<(), Error> { let app = App::new().route("/", web::get().to(index)); diff --git a/basics/nested-routing/src/bin/main.rs b/basics/nested-routing/src/bin/main.rs index e3393873..e6569d25 100644 --- a/basics/nested-routing/src/bin/main.rs +++ b/basics/nested-routing/src/bin/main.rs @@ -1,5 +1,4 @@ use actix_web::{middleware, App, HttpServer}; - use nested_routing::app_config::config_app; #[actix_web::main] diff --git a/basics/nested-routing/src/handlers/products.rs b/basics/nested-routing/src/handlers/products.rs index 1e59fb32..af4c2620 100644 --- a/basics/nested-routing/src/handlers/products.rs +++ b/basics/nested-routing/src/handlers/products.rs @@ -20,13 +20,14 @@ pub async fn remove_product(_id: web::Path) -> Result Result { let _stmt = include_str!("../sql/add_user.sql"); let _stmt = _stmt.replace("$table_fields", &User::sql_table_fields()); @@ -80,10 +81,11 @@ mod db { } mod handlers { - use crate::{db, errors::MyError, models::User}; use actix_web::{web, Error, HttpResponse}; use deadpool_postgres::{Client, Pool}; + use crate::{db, errors::MyError, models::User}; + pub async fn add_user( user: web::Json, db_pool: web::Data, @@ -98,13 +100,14 @@ mod handlers { } } -use crate::config::ExampleConfig; use ::config::Config; use actix_web::{web, App, HttpServer}; use dotenv::dotenv; use handlers::add_user; use tokio_postgres::NoTls; +use crate::config::ExampleConfig; + #[actix_web::main] async fn main() -> std::io::Result<()> { dotenv().ok(); diff --git a/databases/sqlite/src/db.rs b/databases/sqlite/src/db.rs index d2fd0d7b..3ceb92b6 100644 --- a/databases/sqlite/src/db.rs +++ b/databases/sqlite/src/db.rs @@ -1,7 +1,8 @@ +use std::{thread::sleep, time::Duration}; + use actix_web::{error, web, Error}; use rusqlite::Statement; use serde::{Deserialize, Serialize}; -use std::{thread::sleep, time::Duration}; pub type Pool = r2d2::Pool; pub type Connection = r2d2::PooledConnection; diff --git a/forms/form/src/main.rs b/forms/form/src/main.rs index 2c4bef3a..7922ec53 100644 --- a/forms/form/src/main.rs +++ b/forms/form/src/main.rs @@ -1,6 +1,5 @@ -use serde::{Deserialize, Serialize}; - use actix_web::{middleware, web, App, HttpRequest, HttpResponse, HttpServer, Responder, Result}; +use serde::{Deserialize, Serialize}; struct AppState { foo: String, @@ -71,13 +70,14 @@ async fn handle_post_3(req: HttpRequest, params: web::Form) -> impl Re #[cfg(test)] mod tests { - use super::*; use actix_web::body::to_bytes; use actix_web::dev::{Service, ServiceResponse}; use actix_web::http::{header::HeaderValue, header::CONTENT_TYPE, StatusCode}; use actix_web::test::{self, TestRequest}; use actix_web::web::{Bytes, Form}; + use super::*; + trait BodyTest { fn as_str(&self) -> &str; } diff --git a/forms/multipart-s3/src/utils/s3.rs b/forms/multipart-s3/src/utils/s3.rs index 8a354c92..dba73a37 100644 --- a/forms/multipart-s3/src/utils/s3.rs +++ b/forms/multipart-s3/src/utils/s3.rs @@ -1,7 +1,7 @@ +use std::io::Read as _; + use rusoto_core::Region; -use rusoto_s3::S3; -use rusoto_s3::{DeleteObjectRequest, PutObjectRequest, S3Client}; -use std::io::Read; +use rusoto_s3::{DeleteObjectRequest, PutObjectRequest, S3Client, S3}; pub struct Client { #[allow(dead_code)] diff --git a/forms/multipart-s3/src/utils/upload.rs b/forms/multipart-s3/src/utils/upload.rs index dd5be03f..22f256be 100644 --- a/forms/multipart-s3/src/utils/upload.rs +++ b/forms/multipart-s3/src/utils/upload.rs @@ -1,10 +1,11 @@ -use crate::utils::s3::Client; +use std::{convert::From, io::Write}; + use actix_multipart::{Field, Multipart}; use actix_web::{web, web::Bytes, Error}; use futures_util::StreamExt as _; use serde::{Deserialize, Serialize}; -use std::convert::From; -use std::io::Write; + +use crate::utils::s3::Client; #[derive(Deserialize, Serialize, Debug, Clone)] pub struct UploadFile { diff --git a/graphql/juniper-advanced/src/schemas/root.rs b/graphql/juniper-advanced/src/schemas/root.rs index 420e9567..98194d78 100644 --- a/graphql/juniper-advanced/src/schemas/root.rs +++ b/graphql/juniper-advanced/src/schemas/root.rs @@ -3,11 +3,12 @@ use juniper::{ }; use mysql::{from_row, params, Error as DBError, Row}; +use super::{ + product::{Product, ProductInput}, + user::{User, UserInput}, +}; use crate::db::Pool; -use super::product::{Product, ProductInput}; -use super::user::{User, UserInput}; - pub struct Context { pub dbpool: Pool, } diff --git a/json/json/src/main.rs b/json/json/src/main.rs index b6754c20..da957831 100644 --- a/json/json/src/main.rs +++ b/json/json/src/main.rs @@ -84,10 +84,9 @@ async fn main() -> std::io::Result<()> { #[cfg(test)] mod tests { + use actix_web::{body::to_bytes, dev::Service, http, test, web, App}; + use super::*; - use actix_web::body::to_bytes; - use actix_web::dev::Service; - use actix_web::{http, test, web, App}; #[actix_web::test] async fn test_index() { diff --git a/rustfmt.toml b/rustfmt.toml index 44148a2d..38b9e24d 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1 +1,2 @@ reorder_imports = true +group_imports = "StdExternalCrate" diff --git a/shutdown-server/src/main.rs b/shutdown-server/src/main.rs index 648f19a8..f1233140 100644 --- a/shutdown-server/src/main.rs +++ b/shutdown-server/src/main.rs @@ -1,6 +1,7 @@ -use actix_web::{get, middleware, post, web, App, HttpResponse, HttpServer}; use std::{sync::mpsc, thread}; +use actix_web::{get, middleware, post, web, App, HttpResponse, HttpServer}; + #[get("/hello")] async fn hello() -> &'static str { "Hello world!" diff --git a/templating/handlebars/src/main.rs b/templating/handlebars/src/main.rs index 2d5dca88..7b70ac0c 100644 --- a/templating/handlebars/src/main.rs +++ b/templating/handlebars/src/main.rs @@ -1,12 +1,15 @@ -use actix_web::body::BoxBody; -use actix_web::dev::ServiceResponse; -use actix_web::http::header::ContentType; -use actix_web::http::StatusCode; -use actix_web::middleware::{ErrorHandlerResponse, ErrorHandlers}; -use actix_web::{get, web, App, HttpResponse, HttpServer, Result}; +use std::io; + +use actix_web::{ + body::BoxBody, + dev::ServiceResponse, + get, + http::{header::ContentType, StatusCode}, + middleware::{ErrorHandlerResponse, ErrorHandlers}, + web, App, HttpResponse, HttpServer, Result, +}; use handlebars::Handlebars; use serde_json::json; -use std::io; // Macro documentation can be found in the actix_web_codegen crate #[get("/")] diff --git a/templating/tera/src/main.rs b/templating/tera/src/main.rs index b59be2fe..24a0b187 100644 --- a/templating/tera/src/main.rs +++ b/templating/tera/src/main.rs @@ -1,10 +1,13 @@ -use actix_web::body::BoxBody; -use actix_web::dev::ServiceResponse; -use actix_web::http::header::ContentType; -use actix_web::http::StatusCode; -use actix_web::middleware::{ErrorHandlerResponse, ErrorHandlers}; -use actix_web::{error, middleware, web, App, Error, HttpResponse, HttpServer, Result}; use std::collections::HashMap; + +use actix_web::{ + body::BoxBody, + dev::ServiceResponse, + error, + http::{header::ContentType, StatusCode}, + middleware::{self, ErrorHandlerResponse, ErrorHandlers}, + web, App, Error, HttpResponse, HttpServer, Result, +}; use tera::Tera; // store tera template in application state diff --git a/websockets/chat-tcp/src/server.rs b/websockets/chat-tcp/src/server.rs index 2ccd628d..6e699dcc 100644 --- a/websockets/chat-tcp/src/server.rs +++ b/websockets/chat-tcp/src/server.rs @@ -2,9 +2,10 @@ //! And manages available rooms. Peers send messages to other peers in same //! room through `ChatServer`. +use std::collections::{HashMap, HashSet}; + use actix::prelude::*; use rand::{self, rngs::ThreadRng, Rng}; -use std::collections::{HashMap, HashSet}; use crate::session;