Skip to content

Commit

Permalink
applied clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
idky137 committed Oct 8, 2024
1 parent 666808a commit 9f14dba
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 23 deletions.
2 changes: 1 addition & 1 deletion zaino-fetch/src/primitives/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl FromHex for SerializedBlock {
type Error = hex::FromHexError;

fn from_hex<T: AsRef<[u8]>>(hex: T) -> Result<Self, Self::Error> {
hex::decode(hex).map(|bytes| SerializedBlock::from(bytes))
hex::decode(hex).map(SerializedBlock::from)
}
}

Expand Down
4 changes: 2 additions & 2 deletions zaino-nym/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ impl From<NymError> for tonic::Status {
tonic::Status::internal(format!("Connection error: {}", e))
}
NymError::EmptyMessageError => {
tonic::Status::internal(format!("Empty message received from nym mixnet"))
tonic::Status::internal("Empty message received from nym mixnet".to_string())
}
NymError::EmptyRecipientTagError => {
tonic::Status::internal(format!("No AnonSenderTag received from nym mixnet"))
tonic::Status::internal("No AnonSenderTag received from nym mixnet".to_string())
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion zaino-nym/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn read_nym_method(data: &[u8]) -> Result<(String, &[u8]), NymError> {
fn check_nym_body(data: &[u8]) -> Result<&[u8], NymError> {
let mut cursor = Cursor::new(data);
let body_len = CompactSize::read(&mut cursor).map_err(ParseError::Io)? as usize;
if &body_len != &data[cursor.position() as usize..].len() {
if body_len != data[cursor.position() as usize..].len() {
return Err(NymError::ParseError(ParseError::InvalidData(
"Incorrect request body size read.".to_string(),
)));
Expand Down
1 change: 1 addition & 0 deletions zaino-serve/src/server/director.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub struct Server {

impl Server {
/// Spawns a new Server.
#[allow(clippy::too_many_arguments)]
pub async fn spawn(
tcp_active: bool,
tcp_ingestor_listen_addr: Option<SocketAddr>,
Expand Down
12 changes: 7 additions & 5 deletions zaino-serve/src/server/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub(crate) struct Worker {

impl Worker {
/// Creates a new queue worker.
#[allow(clippy::too_many_arguments)]
pub(crate) async fn spawn(
_worker_id: usize,
queue: QueueReceiver<ZingoIndexerRequest>,
Expand Down Expand Up @@ -234,6 +235,7 @@ pub(crate) struct WorkerPool {

impl WorkerPool {
/// Creates a new worker pool containing [idle_workers] workers.
#[allow(clippy::too_many_arguments)]
pub(crate) async fn spawn(
max_size: u16,
idle_size: u16,
Expand Down Expand Up @@ -322,24 +324,24 @@ impl WorkerPool {
self.status.statuses[worker_index].store(5);
self.workers.pop();
self.status.workers.fetch_sub(1, Ordering::SeqCst);
return Ok(());
Ok(())
}
Err(e) => {
self.status.statuses[worker_index].store(6);
eprintln!("Worker returned error on shutdown: {}", e);
// TODO: Handle the inner WorkerError. Return error.
self.status.workers.fetch_sub(1, Ordering::SeqCst);
return Ok(());
Ok(())
}
},
Err(e) => {
self.status.statuses[worker_index].store(6);
eprintln!("Worker returned error on shutdown: {}", e);
// TODO: Handle the JoinError. Return error.
self.status.workers.fetch_sub(1, Ordering::SeqCst);
return Ok(());
Ok(())
}
};
}
}
}

Expand Down Expand Up @@ -370,7 +372,7 @@ impl WorkerPool {
/// Shuts down all the workers in the pool.
pub(crate) async fn shutdown(
&mut self,
worker_handles: &mut Vec<Option<tokio::task::JoinHandle<Result<(), WorkerError>>>>,
worker_handles: &mut [Option<tokio::task::JoinHandle<Result<(), WorkerError>>>],
) {
for i in (0..self.workers.len()).rev() {
self.workers[i].shutdown().await;
Expand Down
14 changes: 10 additions & 4 deletions zaino-testutils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,11 @@ fn set_custom_drops(
eprintln!("Failed to delete temporary wallet directory: {:?}.", e);
}
}
// Assures tests fail on secondary thread panics.
assert!(false);
// Ensures tests fail on secondary thread panics.
#[allow(clippy::assertions_on_constants)]
{
assert!(false);
}
std::process::exit(0);
}));

Expand All @@ -208,8 +211,11 @@ fn set_custom_drops(
eprintln!("Failed to delete temporary wallet directory: {:?}.", e);
}
}
// Assures tests fail on ctrlc exit.
assert!(false);
// Ensures tests fail on ctrlc exit.
#[allow(clippy::assertions_on_constants)]
{
assert!(false);
}
std::process::exit(0);
})
.expect("Error setting Ctrl-C handler");
Expand Down
8 changes: 4 additions & 4 deletions zaino-wallet/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,10 @@ where
Ok(tonic::Response::new(response))
}
Err(e) => {
return Err(Status::invalid_argument(format!(
Err(Status::invalid_argument(format!(
"Failed to parse nym address: {}",
e
)));
)))
}
}
}
Expand Down Expand Up @@ -440,10 +440,10 @@ where
Ok(tonic::Response::new(response))
}
Err(e) => {
return Err(Status::invalid_argument(format!(
Err(Status::invalid_argument(format!(
"Failed to parse nym address: {}",
e
)));
)))
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions zainod/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,10 @@ impl IndexerConfig {
"Invalid nym conf path syntax or non-UTF-8 characters in path.".to_string(),
));
}
} else {
if self.nym_active {
return Err(IndexerError::ConfigError(
"NYM is active but no conf path provided.".to_string(),
));
}
} else if self.nym_active {
return Err(IndexerError::ConfigError(
"NYM is active but no conf path provided.".to_string(),
));
}
Ok(())
}
Expand Down

0 comments on commit 9f14dba

Please sign in to comment.