Skip to content

Commit 4b7c8dd

Browse files
fix: fix clippy pipeline
1 parent a6ab673 commit 4b7c8dd

2 files changed

Lines changed: 29 additions & 12 deletions

File tree

src/routing_handler.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ mod routing_handler_tests {
480480
}
481481

482482
#[test]
483-
/// Tests handling a FloodResponse
483+
/// Tests handling a `FloodResponse`
484484
fn test_handle_flood_response() {
485485
let (sender, _receiver) = unbounded();
486486
let mut handler = RoutingHandler::new(1, NodeType::Client, HashMap::new(), sender);
@@ -513,7 +513,7 @@ mod routing_handler_tests {
513513
}
514514

515515
#[test]
516-
/// Tests handling an Ack
516+
/// Tests handling an `Ack`
517517
fn test_handle_ack() {
518518
let (sender, _receiver) = unbounded();
519519
let mut handler = RoutingHandler::new(1, NodeType::Client, HashMap::new(), sender);
@@ -541,7 +541,7 @@ mod routing_handler_tests {
541541
}
542542

543543
#[test]
544-
/// Tests the network_view update functionality after receiving a FloodResponse
544+
/// Tests the `network_view` update functionality after receiving a `FloodResponse`
545545
fn test_flood_response_network_update() {
546546
let (mut handler, _) = create_test_routing_handler();
547547
handler.flood_counter = 5;
@@ -562,7 +562,7 @@ mod routing_handler_tests {
562562
}
563563

564564
#[test]
565-
/// Tests ErrorInRouting Nack handling
565+
/// Tests `ErrorInRouting` Nack handling
566566
fn test_nack_handling_error_recovery() {
567567
let (mut handler, _) = create_test_routing_handler();
568568

@@ -592,7 +592,7 @@ mod routing_handler_tests {
592592
}
593593

594594
#[test]
595-
/// Tests retry_send
595+
/// Tests `retry_send`
596596
fn test_retry_send_mechanism() {
597597
let (mut handler, _) = create_test_routing_handler();
598598

src/types.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ pub struct MediaFile {
9090
}
9191

9292
impl MediaFile {
93+
#[must_use]
9394
pub fn new(title: String, content: Vec<Bytes>) -> Self {
9495
Self {
9596
id: Uuid::new_v4(),
@@ -98,26 +99,30 @@ impl MediaFile {
9899
}
99100
}
100101

101-
pub fn from_u8(filename: String, data: Vec<u8>) -> Self {
102+
#[must_use]
103+
pub fn from_u8(filename: String, data: &[u8]) -> Self {
102104
let chunk_size = 1024;
103105
let content: Vec<Bytes> = data
104106
.chunks(chunk_size)
105-
.map(|chunk| chunk.to_vec())
107+
.map(<[u8]>::to_vec)
106108
.collect();
107109

108110
Self::new(filename, content)
109111
}
110112

113+
#[must_use]
111114
pub fn get_title(&self) -> &str {
112115
&self.title
113116
}
114117

118+
#[must_use]
115119
pub fn get_content(&self) -> &Vec<Bytes> {
116120
&self.content
117121
}
118122

123+
#[must_use]
119124
pub fn get_size(&self) -> usize {
120-
self.content.iter().map(|chunk| chunk.len()).sum()
125+
self.content.iter().map(Vec::len).sum()
121126
}
122127
}
123128

@@ -317,29 +322,41 @@ pub enum ServerType {
317322
}
318323

319324
pub mod file_conversion {
320-
use super::*;
325+
use super::{MediaFile, TextFile};
321326
use std::fs;
322327
use std::path::Path;
323328

329+
/// Converts a file path into a `MediaFile`.
330+
///
331+
/// # Errors
332+
///
333+
/// Returns an error if the file cannot be read, parsed, or converted
334+
/// into a `MediaFile`.
324335
pub fn file_to_media_file(file_path: &str) -> Result<MediaFile, Box<dyn std::error::Error>> {
325336
let filename = Path::new(file_path)
326337
.file_name()
327338
.and_then(|name| name.to_str())
328339
.unwrap_or("unknown")
329340
.to_string();
330341

331-
let data = fs::read(file_path.to_string())?;
332-
Ok(MediaFile::from_u8(filename, data))
342+
let data = fs::read(file_path)?;
343+
Ok(MediaFile::from_u8(filename, &data))
333344
}
334345

346+
/// Converts a file path into a `TextFile`.
347+
///
348+
/// # Errors
349+
///
350+
/// Returns an error if the file cannot be read, parsed, or converted
351+
/// into a `TextFile`.
335352
pub fn file_to_text_file(file_path: &str) -> Result<TextFile, Box<dyn std::error::Error>> {
336353
let filename = Path::new(file_path)
337354
.file_stem()
338355
.and_then(|name| name.to_str())
339356
.unwrap_or("unknown")
340357
.to_string();
341358

342-
let content = fs::read_to_string(file_path.to_string())?;
359+
let content = fs::read_to_string(file_path)?;
343360

344361
Ok(TextFile::new(filename, content, vec![]))
345362
}

0 commit comments

Comments
 (0)