Skip to content

Commit 57bf200

Browse files
committed
formatting: format the world!
1 parent 498c32b commit 57bf200

34 files changed

+682
-543
lines changed

src/api/server.rs

+150-157
Large diffs are not rendered by default.

src/config.rs

+43-36
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std;
21
use std::collections::HashMap;
32
use std::fs;
43
use std::net::IpAddr;
@@ -8,7 +7,7 @@ use std::str::FromStr;
87
use config::{Config, ConfigError, File};
98
use serde::{Deserialize, Serialize};
109
use serde_with::{serde_as, NoneAsEmptyString};
11-
use toml;
10+
use {std, toml};
1211

1312
use crate::databases::database::DatabaseDrivers;
1413
use crate::mode::TrackerMode;
@@ -70,24 +69,21 @@ impl std::fmt::Display for ConfigurationError {
7069
match self {
7170
ConfigurationError::IOError(e) => e.fmt(f),
7271
ConfigurationError::ParseError(e) => e.fmt(f),
73-
_ => write!(f, "{:?}", self)
72+
_ => write!(f, "{:?}", self),
7473
}
7574
}
7675
}
7776

7877
impl std::error::Error for ConfigurationError {}
7978

8079
impl Configuration {
81-
8280
pub fn get_ext_ip(&self) -> Option<IpAddr> {
8381
match &self.external_ip {
8482
None => None,
85-
Some(external_ip) => {
86-
match IpAddr::from_str(external_ip) {
87-
Ok(external_ip) => Some(external_ip),
88-
Err(_) => None
89-
}
90-
}
83+
Some(external_ip) => match IpAddr::from_str(external_ip) {
84+
Ok(external_ip) => Some(external_ip),
85+
Err(_) => None,
86+
},
9187
}
9288
}
9389

@@ -111,24 +107,23 @@ impl Configuration {
111107
http_api: HttpApiConfig {
112108
enabled: true,
113109
bind_address: String::from("127.0.0.1:1212"),
114-
access_tokens: [(String::from("admin"), String::from("MyAccessToken"))].iter().cloned().collect(),
110+
access_tokens: [(String::from("admin"), String::from("MyAccessToken"))]
111+
.iter()
112+
.cloned()
113+
.collect(),
115114
},
116115
};
117-
configuration.udp_trackers.push(
118-
UdpTrackerConfig {
119-
enabled: false,
120-
bind_address: String::from("0.0.0.0:6969"),
121-
}
122-
);
123-
configuration.http_trackers.push(
124-
HttpTrackerConfig {
125-
enabled: false,
126-
bind_address: String::from("0.0.0.0:6969"),
127-
ssl_enabled: false,
128-
ssl_cert_path: None,
129-
ssl_key_path: None,
130-
}
131-
);
116+
configuration.udp_trackers.push(UdpTrackerConfig {
117+
enabled: false,
118+
bind_address: String::from("0.0.0.0:6969"),
119+
});
120+
configuration.http_trackers.push(HttpTrackerConfig {
121+
enabled: false,
122+
bind_address: String::from("0.0.0.0:6969"),
123+
ssl_enabled: false,
124+
ssl_cert_path: None,
125+
ssl_key_path: None,
126+
});
132127
configuration
133128
}
134129

@@ -142,10 +137,14 @@ impl Configuration {
142137
eprintln!("Creating config file..");
143138
let config = Configuration::default();
144139
let _ = config.save_to_file(path);
145-
return Err(ConfigError::Message(format!("Please edit the config.TOML in the root folder and restart the tracker.")));
140+
return Err(ConfigError::Message(format!(
141+
"Please edit the config.TOML in the root folder and restart the tracker."
142+
)));
146143
}
147144

148-
let torrust_config: Configuration = config.try_into().map_err(|e| ConfigError::Message(format!("Errors while processing config: {}.", e)))?;
145+
let torrust_config: Configuration = config
146+
.try_into()
147+
.map_err(|e| ConfigError::Message(format!("Errors while processing config: {}.", e)))?;
149148

150149
Ok(torrust_config)
151150
}
@@ -193,7 +192,11 @@ mod tests {
193192
194193
[http_api.access_tokens]
195194
admin = "MyAccessToken"
196-
"#.lines().map(|line| line.trim_start()).collect::<Vec<&str>>().join("\n");
195+
"#
196+
.lines()
197+
.map(|line| line.trim_start())
198+
.collect::<Vec<&str>>()
199+
.join("\n");
197200
config
198201
}
199202

@@ -219,11 +222,12 @@ mod tests {
219222

220223
#[test]
221224
fn configuration_should_be_saved_in_a_toml_config_file() {
222-
use std::env;
223-
use crate::Configuration;
224-
use std::fs;
225+
use std::{env, fs};
226+
225227
use uuid::Uuid;
226228

229+
use crate::Configuration;
230+
227231
// Build temp config file path
228232
let temp_directory = env::temp_dir();
229233
let temp_file = temp_directory.join(format!("test_config_{}.toml", Uuid::new_v4()));
@@ -234,24 +238,27 @@ mod tests {
234238

235239
let default_configuration = Configuration::default();
236240

237-
default_configuration.save_to_file(&path).expect("Could not save configuration to file");
241+
default_configuration
242+
.save_to_file(&path)
243+
.expect("Could not save configuration to file");
238244

239245
let contents = fs::read_to_string(&path).expect("Something went wrong reading the file");
240246

241247
assert_eq!(contents, default_config_toml());
242248
}
243249

244250
#[cfg(test)]
245-
fn create_temp_config_file_with_default_config()-> String {
251+
fn create_temp_config_file_with_default_config() -> String {
246252
use std::env;
247253
use std::fs::File;
248254
use std::io::Write;
255+
249256
use uuid::Uuid;
250257

251258
// Build temp config file path
252259
let temp_directory = env::temp_dir();
253260
let temp_file = temp_directory.join(format!("test_config_{}.toml", Uuid::new_v4()));
254-
261+
255262
// Convert to argument type for Configuration::load_from_file
256263
let config_file_path = temp_file.clone();
257264
let path = config_file_path.to_string_lossy().to_string();
@@ -282,4 +289,4 @@ mod tests {
282289

283290
assert_eq!(format!("{}", error), "TrackerModeIncompatible");
284291
}
285-
}
292+
}

src/databases/database.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ use async_trait::async_trait;
22
use derive_more::{Display, Error};
33
use serde::{Deserialize, Serialize};
44

5-
use crate::InfoHash;
6-
use crate::tracker::key::AuthKey;
75
use crate::databases::mysql::MysqlDatabase;
86
use crate::databases::sqlite::SqliteDatabase;
7+
use crate::tracker::key::AuthKey;
8+
use crate::InfoHash;
99

1010
#[derive(Serialize, Deserialize, PartialEq, Debug)]
1111
pub enum DatabaseDrivers {
@@ -70,7 +70,7 @@ impl From<r2d2_sqlite::rusqlite::Error> for Error {
7070
fn from(e: r2d2_sqlite::rusqlite::Error) -> Self {
7171
match e {
7272
r2d2_sqlite::rusqlite::Error::QueryReturnedNoRows => Error::QueryReturnedNoRows,
73-
_ => Error::InvalidQuery
73+
_ => Error::InvalidQuery,
7474
}
7575
}
7676
}

src/databases/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1+
pub mod database;
12
pub mod mysql;
23
pub mod sqlite;
3-
pub mod database;

0 commit comments

Comments
 (0)