From 89789c196b10ae2c0c47492385bd574ce302ac31 Mon Sep 17 00:00:00 2001 From: Mo8it Date: Fri, 16 Dec 2022 18:27:58 +0100 Subject: [PATCH] Refactor imports --- src/config.rs | 4 +--- src/db.rs | 8 +++++--- src/errors.rs | 6 ++++-- src/mailer.rs | 11 ++++++----- src/main.rs | 16 ++++++++++------ src/routes.rs | 12 ++++++------ 6 files changed, 32 insertions(+), 25 deletions(-) diff --git a/src/config.rs b/src/config.rs index 13ba8f9..dbe3b74 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,8 +1,6 @@ use anyhow::{Context, Result}; use serde::Deserialize; -use std::env; -use std::fs::File; -use std::io::BufReader; +use std::{env, fs::File, io::BufReader}; #[derive(Deserialize)] pub struct SocketAddress { diff --git a/src/db.rs b/src/db.rs index 97f60a7..6c32bae 100644 --- a/src/db.rs +++ b/src/db.rs @@ -7,9 +7,11 @@ use diesel::{ use std::env; use tracing::error; -use crate::config::Hook; -use crate::models::{HookLog, NewHookLog}; -use crate::schema::hooklog; +use crate::{ + config::Hook, + models::{HookLog, NewHookLog}, + schema::hooklog, +}; type DBConnectionManager = ConnectionManager; pub type DBPool = Pool; diff --git a/src/errors.rs b/src/errors.rs index 2106a8f..ee91a77 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,5 +1,7 @@ -use axum::http::StatusCode; -use axum::response::{IntoResponse, Response}; +use axum::{ + http::StatusCode, + response::{IntoResponse, Response}, +}; use tracing::error; pub struct AppError(anyhow::Error); diff --git a/src/mailer.rs b/src/mailer.rs index dc0e4e8..2603792 100644 --- a/src/mailer.rs +++ b/src/mailer.rs @@ -1,9 +1,10 @@ use anyhow::{Context, Result}; -use lettre::address::Address; -use lettre::message::{Mailbox, MessageBuilder}; -use lettre::transport::smtp::authentication::Credentials; -use lettre::Transport; -use lettre::{Message, SmtpTransport}; +use lettre::{ + address::Address, + message::{Mailbox, Message, MessageBuilder}, + transport::{smtp::authentication::Credentials, Transport}, + SmtpTransport, +}; use std::mem; use crate::config; diff --git a/src/main.rs b/src/main.rs index a708548..dd19f3a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,11 +10,15 @@ mod states; mod templates; use anyhow::Result; -use axum::routing::{get, post}; -use axum::{Router, Server}; +use axum::{ + routing::{get, post}, + Router, Server, +}; use axum_extra::routing::SpaRouter; -use std::net::{IpAddr, Ipv4Addr, SocketAddr}; -use std::process; +use std::{ + net::{IpAddr, Ipv4Addr, SocketAddr}, + process, +}; use tracing::info; async fn init() -> Result<()> { @@ -54,8 +58,8 @@ async fn init() -> Result<()> { #[tokio::main] async fn main() { - init().await.unwrap_or_else(|e| { + if let Err(e) = init().await { eprintln!("{e:?}"); process::exit(1); - }); + }; } diff --git a/src/routes.rs b/src/routes.rs index 8cecb03..b20f582 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -1,16 +1,16 @@ use anyhow::Context; use askama_axum::IntoResponse; -use axum::extract::{Query, State}; -use axum::http::header::HeaderMap; -use axum::response::Response; +use axum::{ + extract::{Query, State}, + http::header::HeaderMap, + response::Response, +}; use bytes::Bytes; use hmac::{Hmac, Mac}; use serde::Deserialize; use serde_json::Value; use sha2::Sha256; -use std::process::Command; -use std::sync::Arc; -use std::thread; +use std::{process::Command, sync::Arc, thread}; use tracing::{error, info}; use crate::{db, errors, mailer, states, templates};