Skip to content

Commit fe25778

Browse files
committed
chore: udpate rust toolchain 1.72.0-nightly
Fixing cargo fmt and clipply errors and warnings
1 parent 96f17c7 commit fe25778

File tree

23 files changed

+474
-392
lines changed

23 files changed

+474
-392
lines changed

Cargo.lock

Lines changed: 338 additions & 375 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ pub struct Running {
2828
pub tracker_data_importer_handle: tokio::task::JoinHandle<()>,
2929
}
3030

31+
/// Runs the application.
32+
///
33+
/// # Panics
34+
///
35+
/// It panics if there is an error connecting to the database.
3136
#[allow(clippy::too_many_lines)]
3237
pub async fn run(configuration: Configuration, api_version: &Version) -> Running {
3338
let log_level = configuration.settings.read().await.log_level.clone();

src/cache/image/manager.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ pub enum Error {
1919

2020
type UserQuotas = HashMap<i64, ImageCacheQuota>;
2121

22+
/// Returns the current time in seconds.
23+
///
24+
/// # Panics
25+
///
26+
/// This function will panic if the current time is before the UNIX EPOCH.
2227
#[must_use]
2328
pub fn now_in_secs() -> u64 {
2429
SystemTime::now()
@@ -87,6 +92,11 @@ pub struct ImageCacheService {
8792
}
8893

8994
impl ImageCacheService {
95+
/// Create a new image cache service.
96+
///
97+
/// # Panics
98+
///
99+
/// This function will panic if the image cache could not be created.
90100
pub async fn new(cfg: Arc<Configuration>) -> Self {
91101
let settings = cfg.settings.read().await;
92102

src/cache/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl BytesCache {
9898
pub fn total_size(&self) -> usize {
9999
let mut size: usize = 0;
100100

101-
for (_, entry) in self.bytes_table.iter() {
101+
for (_, entry) in &self.bytes_table {
102102
size += entry.bytes.len();
103103
}
104104

src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,10 @@ impl Configuration {
362362
}
363363

364364
/// Returns the save to file of this [`Configuration`].
365+
///
366+
/// # Panics
367+
///
368+
/// This function will panic if it can't write to the file.
365369
pub async fn save_to_file(&self, config_path: &str) {
366370
let settings = self.settings.read().await;
367371

src/console/commands/import_tracker_statistics.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ fn print_usage() {
7070
);
7171
}
7272

73+
/// Import Tracker Statistics Command
74+
///
75+
/// # Panics
76+
///
77+
/// Panics if arguments cannot be parsed.
7378
pub async fn run_importer() {
7479
parse_args().expect("unable to parse command arguments");
7580
import().await;

src/databases/mysql.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ impl Database for Mysql {
329329
let category_filter_query = if let Some(c) = categories {
330330
let mut i = 0;
331331
let mut category_filters = String::new();
332-
for category in c.iter() {
332+
for category in c {
333333
// don't take user input in the db query
334334
if let Ok(sanitized_category) = self.get_category_from_name(category).await {
335335
let mut str = format!("tc.name = '{}'", sanitized_category.name);
@@ -352,7 +352,7 @@ impl Database for Mysql {
352352
let tag_filter_query = if let Some(t) = tags {
353353
let mut i = 0;
354354
let mut tag_filters = String::new();
355-
for tag in t.iter() {
355+
for tag in t {
356356
// don't take user input in the db query
357357
if let Ok(sanitized_tag) = self.get_tag_from_name(tag).await {
358358
let mut str = format!("tl.tag_id = '{}'", sanitized_tag.tag_id);
@@ -479,7 +479,7 @@ impl Database for Mysql {
479479
} else {
480480
let files = torrent.info.files.as_ref().unwrap();
481481

482-
for file in files.iter() {
482+
for file in files {
483483
let path = file.path.join("/");
484484

485485
let _ = query("INSERT INTO torrust_torrent_files (md5sum, torrent_id, length, path) VALUES (?, ?, ?, ?)")

src/databases/sqlite.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ impl Database for Sqlite {
319319
let category_filter_query = if let Some(c) = categories {
320320
let mut i = 0;
321321
let mut category_filters = String::new();
322-
for category in c.iter() {
322+
for category in c {
323323
// don't take user input in the db query
324324
if let Ok(sanitized_category) = self.get_category_from_name(category).await {
325325
let mut str = format!("tc.name = '{}'", sanitized_category.name);
@@ -342,7 +342,7 @@ impl Database for Sqlite {
342342
let tag_filter_query = if let Some(t) = tags {
343343
let mut i = 0;
344344
let mut tag_filters = String::new();
345-
for tag in t.iter() {
345+
for tag in t {
346346
// don't take user input in the db query
347347
if let Ok(sanitized_tag) = self.get_tag_from_name(tag).await {
348348
let mut str = format!("tl.tag_id = '{}'", sanitized_tag.tag_id);
@@ -469,7 +469,7 @@ impl Database for Sqlite {
469469
} else {
470470
let files = torrent.info.files.as_ref().unwrap();
471471

472-
for file in files.iter() {
472+
for file in files {
473473
let path = file.path.join("/");
474474

475475
let _ = query("INSERT INTO torrust_torrent_files (md5sum, torrent_id, length, path) VALUES (?, ?, ?, ?)")

src/mailer.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,15 @@ impl Service {
5858
}
5959
}
6060

61-
/// Send Verification Email
61+
/// Send Verification Email.
6262
///
6363
/// # Errors
6464
///
6565
/// This function will return an error if unable to send an email.
66+
///
67+
/// # Panics
68+
///
69+
/// This function will panic if the multipart builder had an error.
6670
pub async fn send_verification_mail(
6771
&self,
6872
to: &str,

src/models/torrent_file.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ impl TorrentInfo {
5050
}
5151
}
5252

53+
/// It returns the root hash as a `i64` value.
54+
///
55+
/// # Panics
56+
///
57+
/// This function will panic if the root hash cannot be converted into a
58+
/// `i64` value.
5359
#[must_use]
5460
pub fn get_root_hash_as_i64(&self) -> i64 {
5561
match &self.root_hash {
@@ -96,6 +102,11 @@ pub struct Torrent {
96102
}
97103

98104
impl Torrent {
105+
/// It hydrates a `Torrent` struct from the database data.
106+
///
107+
/// # Panics
108+
///
109+
/// This function will panic if the `torrent_info.pieces` is not a valid hex string.
99110
#[must_use]
100111
pub fn from_db_info_files_and_announce_urls(
101112
torrent_info: DbTorrentInfo,
@@ -180,6 +191,11 @@ impl Torrent {
180191
}
181192
}
182193

194+
/// It calculates the info hash of the torrent file.
195+
///
196+
/// # Panics
197+
///
198+
/// This function will panic if the `info` part of the torrent file cannot be serialized.
183199
#[must_use]
184200
pub fn calculate_info_hash_as_bytes(&self) -> [u8; 20] {
185201
let info_bencoded = ser::to_bytes(&self.info).expect("variable `info` was not able to be serialized.");
@@ -204,7 +220,7 @@ impl Torrent {
204220
None => 0,
205221
Some(files) => {
206222
let mut file_size = 0;
207-
for file in files.iter() {
223+
for file in files {
208224
file_size += file.length;
209225
}
210226
file_size
@@ -213,6 +229,11 @@ impl Torrent {
213229
}
214230
}
215231

232+
/// It returns the announce urls of the torrent file.
233+
///
234+
/// # Panics
235+
///
236+
/// This function will panic if both the `announce_list` and the `announce` are `None`.
216237
#[must_use]
217238
pub fn announce_urls(&self) -> Vec<String> {
218239
match &self.announce_list {

0 commit comments

Comments
 (0)