Skip to content

Commit

Permalink
clippy nursery
Browse files Browse the repository at this point in the history
  • Loading branch information
agourlay committed Feb 2, 2025
1 parent cef5886 commit 47e19ae
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
18 changes: 9 additions & 9 deletions src/dlm_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,43 +43,43 @@ impl From<reqwest::Error> for DlmError {
//TODO use Reqwest's types instead of guessing from strings https://github.com/seanmonstar/reqwest/issues/757
let e_string = e.to_string();
if e_string.contains(BODY_ERROR) {
DlmError::ResponseBodyError
Self::ResponseBodyError
} else if e_string.contains(CONNECTION_CLOSED) {
DlmError::ConnectionClosed
Self::ConnectionClosed
} else if e_string.contains(CONNECTION_TIMEOUT) {
DlmError::ConnectionTimeout
Self::ConnectionTimeout
} else {
DlmError::Other { message: e_string }
Self::Other { message: e_string }
}
}
}

impl From<std::io::Error> for DlmError {
fn from(e: std::io::Error) -> Self {
DlmError::StdIoError { e }
Self::StdIoError { e }
}
}

impl From<Elapsed> for DlmError {
fn from(_: Elapsed) -> Self {
DlmError::DeadLineElapsedTimeout
Self::DeadLineElapsedTimeout
}
}

impl From<JoinError> for DlmError {
fn from(e: JoinError) -> Self {
DlmError::TaskError { e }
Self::TaskError { e }
}
}

impl From<async_channel::RecvError> for DlmError {
fn from(e: async_channel::RecvError) -> Self {
DlmError::ChannelError { e }
Self::ChannelError { e }
}
}

impl From<clap::Error> for DlmError {
fn from(e: clap::Error) -> Self {
DlmError::ClapError { e }
Self::ClapError { e }
}
}
4 changes: 2 additions & 2 deletions src/file_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct FileLink {
}

impl FileLink {
pub fn new(url: &str) -> Result<FileLink, DlmError> {
pub fn new(url: &str) -> Result<Self, DlmError> {
let trimmed = url.trim();
if trimmed.is_empty() {
Err(Other {
Expand All @@ -35,7 +35,7 @@ impl FileLink {
Self::extract_extension_from_filename(&last_segment);

let url = url.to_string();
let file_link = FileLink {
let file_link = Self {
url,
filename_without_extension,
extension,
Expand Down
10 changes: 5 additions & 5 deletions src/progress_bar_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct ProgressBarManager {
}

impl ProgressBarManager {
pub async fn init(max_concurrent_downloads: usize, main_pb_len: u64) -> ProgressBarManager {
pub async fn init(max_concurrent_downloads: usize, main_pb_len: u64) -> Self {
let mp = MultiProgress::new();
// Refresh terminal 5 times per seconds
let draw_target = ProgressDrawTarget::stdout_with_hz(5);
Expand Down Expand Up @@ -46,11 +46,11 @@ impl ProgressBarManager {
for _ in 0..file_pb_count {
let file_pb = mp.add(ProgressBar::new(0));
file_pb.set_style(dl_style.clone());
file_pb.set_message(ProgressBarManager::message_progress_bar(PENDING));
file_pb.set_message(Self::message_progress_bar(PENDING));
tx.send(file_pb).await.expect("channel should not fail");
}

ProgressBarManager {
Self {
main_pb,
file_pb_count,
tx,
Expand Down Expand Up @@ -83,7 +83,7 @@ impl ProgressBarManager {
}

pub fn log_above_progress_bars(&self, msg: &str) {
ProgressBarManager::log_above_progress_bar(&self.main_pb, msg);
Self::log_above_progress_bar(&self.main_pb, msg);
}

fn log_above_progress_bar(pb: &ProgressBar, msg: &str) {
Expand All @@ -96,6 +96,6 @@ impl ProgressBarManager {

pub fn reset_progress_bar(pb: &ProgressBar) {
pb.reset();
pb.set_message(ProgressBarManager::message_progress_bar(PENDING));
pb.set_message(Self::message_progress_bar(PENDING));
}
}
2 changes: 1 addition & 1 deletion src/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn retry_handler(e: &DlmError, pbm: &ProgressBarManager, link: &str) -> bool
should_retry
}

fn is_network_error(e: &DlmError) -> bool {
const fn is_network_error(e: &DlmError) -> bool {
matches!(
e,
DlmError::ConnectionClosed
Expand Down

0 comments on commit 47e19ae

Please sign in to comment.