refactor(downloads): ran cargo clippy & cargo fmt

Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
quexeky
2024-11-11 18:27:39 +11:00
parent 17244496ec
commit 5e3d26b3ca
6 changed files with 23 additions and 20 deletions

View File

@ -132,9 +132,10 @@ impl GameDownloadAgent {
return chunk.lengths.iter().sum::<usize>();
})
.sum::<usize>();
let chunk_count = manifest_download.iter().map(|(_, chunk)| {
chunk.lengths.len()
}).sum();
let chunk_count = manifest_download
.values()
.map(|chunk| chunk.lengths.len())
.sum();
self.progress = ProgressObject::new(length.try_into().unwrap(), chunk_count);
if let Ok(mut manifest) = self.manifest.lock() {

View File

@ -75,13 +75,13 @@ impl DropDownloadPipeline<Response, File> {
progress: Arc<AtomicUsize>,
size: usize,
) -> Self {
return Self {
Self {
source,
destination,
control_flag,
progress,
size,
};
}
}
fn copy(&mut self) -> Result<bool, io::Error> {
@ -99,10 +99,8 @@ impl DropDownloadPipeline<Response, File> {
current_size += bytes_read;
buf_writer.write_all(&copy_buf[0..bytes_read])?;
self.progress.fetch_add(
bytes_read.try_into().unwrap(),
std::sync::atomic::Ordering::Relaxed,
);
self.progress
.fetch_add(bytes_read, std::sync::atomic::Ordering::Relaxed);
if current_size == self.size {
break;
@ -114,7 +112,7 @@ impl DropDownloadPipeline<Response, File> {
fn finish(self) -> Result<Digest, io::Error> {
let checksum = self.destination.finish()?;
return Ok(checksum);
Ok(checksum)
}
}
@ -187,5 +185,5 @@ pub fn download_game_chunk(
return Err(GameDownloadError::ChecksumError);
}
return Ok(true);
Ok(true)
}

View File

@ -25,7 +25,6 @@ impl From<bool> for DownloadThreadControlFlag {
}
}
#[derive(Clone)]
pub struct DownloadThreadControl {
inner: Arc<AtomicBool>,

View File

@ -3,4 +3,4 @@ pub mod download_commands;
mod download_logic;
mod download_thread_control_flag;
mod manifest;
mod progress_object;
mod progress_object;

View File

@ -1,4 +1,7 @@
use std::sync::{atomic::{AtomicUsize, Ordering}, Arc};
use std::sync::{
atomic::{AtomicUsize, Ordering},
Arc,
};
#[derive(Clone)]
pub struct ProgressObject {
@ -8,16 +11,17 @@ pub struct ProgressObject {
impl ProgressObject {
pub fn new(max: usize, length: usize) -> Self {
let arr = (0..length).map(|_| { Arc::new(AtomicUsize::new(0)) }).collect();
let arr = (0..length).map(|_| Arc::new(AtomicUsize::new(0))).collect();
Self {
max,
progress_instances: Arc::new(arr)
progress_instances: Arc::new(arr),
}
}
pub fn sum(&self) -> usize {
self.progress_instances.iter().map(|instance| {
instance.load(Ordering::Relaxed)
}).sum()
self.progress_instances
.iter()
.map(|instance| instance.load(Ordering::Relaxed))
.sum()
}
pub fn get_progress(&self) -> f64 {
@ -26,4 +30,4 @@ impl ProgressObject {
pub fn get(&self, index: usize) -> Arc<AtomicUsize> {
self.progress_instances[index].clone()
}
}
}

View File

@ -0,0 +1 @@