Skip to content

Commit

Permalink
Updated rustfmt config. (#53)
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Kirilin <[email protected]>
  • Loading branch information
s3rius authored Mar 6, 2022
1 parent 3a64138 commit bf4fdec
Show file tree
Hide file tree
Showing 31 changed files with 166 additions and 152 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Adding component
run: rustup component add rustfmt
- name: Checking code format
run: cargo fmt -- --check
run: cargo fmt -- --check --config use_try_shorthand=true,imports_granularity=Crate

code_check:
needs: pre_job
Expand Down
3 changes: 3 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ repos:
pass_filenames: false
args:
- fmt
- --
- --config
- use_try_shorthand=true,imports_granularity=Crate

- id: clippy
types:
Expand Down
11 changes: 6 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::ffi::OsString;
use std::path::PathBuf;
use std::{ffi::OsString, path::PathBuf};

use structopt::StructOpt;

use crate::info_storages::AvailableInfoStores;
use crate::notifiers::{Format, Hook};
use crate::protocol::extensions::Extensions;
use crate::{
info_storages::AvailableInfoStores,
notifiers::{Format, Hook},
protocol::extensions::Extensions,
};

use crate::storages::AvailableStores;

Expand Down
3 changes: 1 addition & 2 deletions src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::io::{Error, ErrorKind};

use actix_web::http::StatusCode;
use actix_web::{HttpResponse, HttpResponseBuilder, ResponseError};
use actix_web::{http::StatusCode, HttpResponse, HttpResponseBuilder, ResponseError};
use log::error;

pub type RustusResult<T> = Result<T, RustusError>;
Expand Down
15 changes: 6 additions & 9 deletions src/info_storages/db_info_storage.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use std::time::Duration;

use async_trait::async_trait;
use rbatis::crud::CRUD;
use rbatis::crud_table;
use rbatis::db::DBPoolOptions;
use rbatis::executor::Executor;
use rbatis::rbatis::Rbatis;
use rbatis::{crud::CRUD, crud_table, db::DBPoolOptions, executor::Executor, rbatis::Rbatis};

use crate::errors::{RustusError, RustusResult};
use crate::info_storages::{FileInfo, InfoStorage};
use crate::{
errors::{RustusError, RustusResult},
info_storages::{FileInfo, InfoStorage},
};

#[crud_table]
struct DbModel {
Expand Down Expand Up @@ -84,8 +82,7 @@ impl InfoStorage for DBInfoStorage {
#[cfg(test)]
mod tests {
use super::{DBInfoStorage, DbModel};
use crate::info_storages::FileInfo;
use crate::InfoStorage;
use crate::{info_storages::FileInfo, InfoStorage};
use rbatis::crud::CRUD;

async fn get_info_storage() -> DBInfoStorage {
Expand Down
29 changes: 18 additions & 11 deletions src/info_storages/file_info_storage.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
use std::io::{Read, Write};
use std::path::PathBuf;
use std::{
io::{Read, Write},
path::PathBuf,
};

use async_trait::async_trait;
use log::error;
use std::fs::{remove_file, File, OpenOptions};
use std::io::{BufReader, BufWriter};
use std::{
fs::{remove_file, File, OpenOptions},
io::{BufReader, BufWriter},
};
use tokio::fs::DirBuilder;

use crate::errors::{RustusError, RustusResult};
use crate::info_storages::{FileInfo, InfoStorage};
use crate::{
errors::{RustusError, RustusResult},
info_storages::{FileInfo, InfoStorage},
};

pub struct FileInfoStorage {
info_dir: PathBuf,
Expand Down Expand Up @@ -94,11 +100,12 @@ impl InfoStorage for FileInfoStorage {
#[cfg(test)]
mod tests {
use super::FileInfoStorage;
use crate::info_storages::FileInfo;
use crate::InfoStorage;
use std::collections::HashMap;
use std::fs::File;
use std::io::{Read, Write};
use crate::{info_storages::FileInfo, InfoStorage};
use std::{
collections::HashMap,
fs::File,
io::{Read, Write},
};

#[actix_rt::test]
async fn preparation() {
Expand Down
6 changes: 3 additions & 3 deletions src/info_storages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ pub mod redis_info_storage;

pub mod models;

pub use models::available_info_storages::AvailableInfoStores;
pub use models::file_info::FileInfo;
pub use models::info_store::InfoStorage;
pub use models::{
available_info_storages::AvailableInfoStores, file_info::FileInfo, info_store::InfoStorage,
};
3 changes: 1 addition & 2 deletions src/info_storages/models/available_info_storages.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use derive_more::{Display, From};

use crate::errors::RustusResult;
use crate::{from_str, RustusConf};
use crate::{errors::RustusResult, from_str, RustusConf};

use crate::info_storages::{file_info_storage, InfoStorage};
use strum::EnumIter;
Expand Down
6 changes: 2 additions & 4 deletions src/info_storages/models/file_info.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::collections::HashMap;

use crate::errors::RustusError;
use crate::RustusResult;
use chrono::serde::ts_seconds;
use chrono::{DateTime, Utc};
use crate::{errors::RustusError, RustusResult};
use chrono::{serde::ts_seconds, DateTime, Utc};
use log::error;
use serde::{Deserialize, Serialize};

Expand Down
3 changes: 1 addition & 2 deletions src/info_storages/models/info_store.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::errors::RustusResult;
use crate::info_storages::FileInfo;
use crate::{errors::RustusResult, info_storages::FileInfo};
use async_trait::async_trait;

/// Trait for every info storage.
Expand Down
16 changes: 7 additions & 9 deletions src/info_storages/redis_info_storage.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use async_trait::async_trait;
use mobc_redis::mobc::Pool;
use mobc_redis::redis;
use mobc_redis::RedisConnectionManager;
use mobc_redis::{mobc::Pool, redis, RedisConnectionManager};
use redis::aio::Connection;

use crate::errors::{RustusError, RustusResult};
use crate::info_storages::{FileInfo, InfoStorage};
use crate::{
errors::{RustusError, RustusResult},
info_storages::{FileInfo, InfoStorage},
};

pub struct RedisStorage {
pool: Pool<RedisConnectionManager>,
Expand Down Expand Up @@ -66,10 +66,8 @@ impl InfoStorage for RedisStorage {
#[cfg(feature = "test_redis")]
mod tests {
use super::RedisStorage;
use crate::info_storages::FileInfo;
use crate::InfoStorage;
use mobc_redis::redis;
use mobc_redis::redis::AsyncCommands;
use crate::{info_storages::FileInfo, InfoStorage};
use mobc_redis::{redis, redis::AsyncCommands};

async fn get_storage() -> RedisStorage {
let redis_url = std::env::var("TEST_REDIS_URL").unwrap();
Expand Down
20 changes: 10 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#![cfg_attr(coverage, feature(no_coverage))]

use std::str::FromStr;
use std::sync::Arc;
use std::{str::FromStr, sync::Arc};

use actix_web::{
dev::{Server, Service},
http::Method,
middleware, web, App, HttpServer,
};
use fern::colors::{Color, ColoredLevelConfig};
use fern::Dispatch;
use fern::{
colors::{Color, ColoredLevelConfig},
Dispatch,
};
use log::LevelFilter;

use config::RustusConf;

use crate::errors::RustusResult;
use crate::info_storages::InfoStorage;
use crate::notifiers::models::notification_manager::NotificationManager;
use crate::server::rustus_service;
use crate::state::State;
use crate::storages::Storage;
use crate::{
errors::RustusResult, info_storages::InfoStorage,
notifiers::models::notification_manager::NotificationManager, server::rustus_service,
state::State, storages::Storage,
};

mod config;
mod errors;
Expand Down
17 changes: 9 additions & 8 deletions src/notifiers/amqp_notifier.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use crate::notifiers::{Hook, Notifier};
use crate::RustusResult;
use crate::{
notifiers::{Hook, Notifier},
RustusResult,
};
use actix_web::http::header::HeaderMap;
use async_trait::async_trait;
use lapin::options::{
BasicPublishOptions, ExchangeDeclareOptions, QueueBindOptions, QueueDeclareOptions,
use lapin::{
options::{BasicPublishOptions, ExchangeDeclareOptions, QueueBindOptions, QueueDeclareOptions},
types::FieldTable,
BasicProperties, ConnectionProperties, ExchangeKind,
};
use lapin::types::FieldTable;
use lapin::{BasicProperties, ConnectionProperties, ExchangeKind};
use mobc_lapin::mobc::Pool;
use mobc_lapin::RMQConnectionManager;
use mobc_lapin::{mobc::Pool, RMQConnectionManager};
use strum::IntoEnumIterator;
use tokio_amqp::LapinTokioExt;

Expand Down
14 changes: 9 additions & 5 deletions src/notifiers/dir_notifier.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::errors::RustusError;
use crate::notifiers::{Hook, Notifier};
use crate::RustusResult;
use crate::{
errors::RustusError,
notifiers::{Hook, Notifier},
RustusResult,
};
use actix_web::http::header::HeaderMap;
use async_trait::async_trait;
use log::debug;
Expand Down Expand Up @@ -53,10 +55,12 @@ mod tests {
use super::DirNotifier;
use crate::notifiers::{Hook, Notifier};
use actix_web::http::header::HeaderMap;
use std::fs::File;
use std::io::{Read, Write};
#[cfg(unix)]
use std::os::unix::fs::PermissionsExt;
use std::{
fs::File,
io::{Read, Write},
};
use tempdir::TempDir;

#[actix_rt::test]
Expand Down
14 changes: 9 additions & 5 deletions src/notifiers/file_notifier.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::errors::RustusError;
use crate::notifiers::{Hook, Notifier};
use crate::RustusResult;
use crate::{
errors::RustusError,
notifiers::{Hook, Notifier},
RustusResult,
};
use actix_web::http::header::HeaderMap;
use async_trait::async_trait;
use log::debug;
Expand Down Expand Up @@ -47,10 +49,12 @@ mod tests {
use super::FileNotifier;
use crate::notifiers::{Hook, Notifier};
use actix_web::http::header::HeaderMap;
use std::fs::File;
use std::io::{Read, Write};
#[cfg(unix)]
use std::os::unix::fs::PermissionsExt;
use std::{
fs::File,
io::{Read, Write},
};

#[cfg(unix)]
#[actix_rt::test]
Expand Down
6 changes: 2 additions & 4 deletions src/notifiers/http_notifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@ mod tests {
use super::HttpNotifier;
use crate::notifiers::{Hook, Notifier};
use actix_web::http::header::{HeaderMap, HeaderName, HeaderValue};
use httptest::matchers::contains;
use httptest::responders::status_code;
use std::str::FromStr;
use std::time::Duration;
use httptest::{matchers::contains, responders::status_code};
use std::{str::FromStr, time::Duration};

#[actix_rt::test]
async fn success_request() {
Expand Down
4 changes: 1 addition & 3 deletions src/notifiers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ mod file_notifier;
pub mod http_notifier;
pub mod models;

pub use models::hooks::Hook;
pub use models::message_format::Format;
pub use models::notifier::Notifier;
pub use models::{hooks::Hook, message_format::Format, notifier::Notifier};
6 changes: 2 additions & 4 deletions src/notifiers/models/message_format.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use crate::errors::RustusResult;
use crate::info_storages::FileInfo;
use crate::{errors::RustusResult, info_storages::FileInfo};
use actix_web::HttpRequest;
use derive_more::{Display, From};
use serde::Serialize;
use serde_json::Map;
use serde_json::Value;
use serde_json::{Map, Value};
use std::collections::HashMap;

use crate::from_str;
Expand Down
10 changes: 5 additions & 5 deletions src/notifiers/models/notification_manager.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::errors::RustusResult;
#[cfg(feature = "amqp_notifier")]
use crate::notifiers::amqp_notifier;
use crate::notifiers::dir_notifier::DirNotifier;
use crate::notifiers::file_notifier::FileNotifier;
#[cfg(feature = "http_notifier")]
use crate::notifiers::http_notifier;
use crate::notifiers::{Hook, Notifier};
use crate::RustusConf;
use crate::{
errors::RustusResult,
notifiers::{dir_notifier::DirNotifier, file_notifier::FileNotifier, Hook, Notifier},
RustusConf,
};
use actix_web::http::header::HeaderMap;
use log::debug;

Expand Down
6 changes: 4 additions & 2 deletions src/protocol/core/get_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ mod tests {
use actix_web::http::{Method, StatusCode};

use crate::{rustus_service, State};
use actix_web::test::{call_service, init_service, TestRequest};
use actix_web::{web, App};
use actix_web::{
test::{call_service, init_service, TestRequest},
web, App,
};

#[actix_rt::test]
async fn success() {
Expand Down
6 changes: 2 additions & 4 deletions src/protocol/core/server_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ pub async fn server_info(state: web::Data<State>) -> HttpResponse {

#[cfg(test)]
mod tests {
use crate::protocol::extensions::Extensions;
use crate::{rustus_service, State};
use crate::{protocol::extensions::Extensions, rustus_service, State};
use actix_web::test::{call_service, init_service, TestRequest};

use actix_web::http::Method;
use actix_web::{web, App};
use actix_web::{http::Method, web, App};

#[actix_rt::test]
async fn test_server_info() {
Expand Down
Loading

0 comments on commit bf4fdec

Please sign in to comment.