From 9dafcc3dabb7d99fe685db6b6509672ca40ed9ee Mon Sep 17 00:00:00 2001 From: dastansam Date: Thu, 28 Mar 2024 14:24:13 +0100 Subject: [PATCH] Fmt fix --- pcidss/api/src/transaction.rs | 9 +++-- pcidss/core/src/error.rs | 52 +++++++++++++-------------- pcidss/core/src/transaction/traits.rs | 3 +- pcidss/core/src/types.rs | 20 +++++------ pcidss/core/src/utils.rs | 44 ++++++++++++----------- 5 files changed, 68 insertions(+), 60 deletions(-) diff --git a/pcidss/api/src/transaction.rs b/pcidss/api/src/transaction.rs index c6c81f6..bd3e3cc 100644 --- a/pcidss/api/src/transaction.rs +++ b/pcidss/api/src/transaction.rs @@ -35,9 +35,14 @@ impl TransactionTrait for PgTransaction { Ok(None) } - async fn find_by_bank_account_id(&self, source: &Uuid) -> Result, DomainError> { + async fn find_by_bank_account_id( + &self, + source: &Uuid, + ) -> Result, DomainError> { let client = self.pool.get().await?; - let stmt = client.prepare("SELECT * FROM bank_transaction WHERE source = $1 OR recipient = $1").await?; + let stmt = client + .prepare("SELECT * FROM bank_transaction WHERE source = $1 OR recipient = $1") + .await?; let result = client.query(&stmt, &[&source]).await?; diff --git a/pcidss/core/src/error.rs b/pcidss/core/src/error.rs index 6f1fc00..250060b 100644 --- a/pcidss/core/src/error.rs +++ b/pcidss/core/src/error.rs @@ -8,51 +8,51 @@ use thiserror::Error; #[derive(Debug, Error, PartialEq, Eq)] pub enum DomainError { - #[error("{}", _0)] - NotFound(String), + #[error("{}", _0)] + NotFound(String), - #[error("{}", _0)] - BadRequest(String), + #[error("{}", _0)] + BadRequest(String), - #[error("{}", _0)] - InternalServerError(String), + #[error("{}", _0)] + InternalServerError(String), - #[error("{}", _0)] - ApiError(String), + #[error("{}", _0)] + ApiError(String), } impl From for DomainError { - fn from(err: tokio_postgres::Error) -> Self { - DomainError::InternalServerError(err.to_string()) - } + fn from(err: tokio_postgres::Error) -> Self { + DomainError::InternalServerError(err.to_string()) + } } impl From for DomainError { - fn from(err: deadpool_postgres::PoolError) -> Self { - DomainError::InternalServerError(err.to_string()) - } + fn from(err: deadpool_postgres::PoolError) -> Self { + DomainError::InternalServerError(err.to_string()) + } } impl From for DomainError { - fn from(err: deadpool_postgres::BuildError) -> Self { - DomainError::InternalServerError(err.to_string()) - } + fn from(err: deadpool_postgres::BuildError) -> Self { + DomainError::InternalServerError(err.to_string()) + } } impl From for DomainError { - fn from(err: deadpool_postgres::CreatePoolError) -> Self { - DomainError::InternalServerError(err.to_string()) - } + fn from(err: deadpool_postgres::CreatePoolError) -> Self { + DomainError::InternalServerError(err.to_string()) + } } impl From for DomainError { - fn from(value: IsoError) -> Self { - DomainError::ApiError(value.msg) - } + fn from(value: IsoError) -> Self { + DomainError::ApiError(value.msg) + } } impl From for DomainError { - fn from(value: ParseIntError) -> Self { - DomainError::InternalServerError(value.to_string()) - } + fn from(value: ParseIntError) -> Self { + DomainError::InternalServerError(value.to_string()) + } } diff --git a/pcidss/core/src/transaction/traits.rs b/pcidss/core/src/transaction/traits.rs index 40961da..e1b92ae 100644 --- a/pcidss/core/src/transaction/traits.rs +++ b/pcidss/core/src/transaction/traits.rs @@ -14,7 +14,8 @@ pub trait TransactionTrait: Send + Sync { async fn find_by_id(&self, id: &Uuid) -> Result, DomainError>; /// Find by beneficiary. - async fn find_by_bank_account_id(&self, source: &Uuid) -> Result, DomainError>; + async fn find_by_bank_account_id(&self, source: &Uuid) + -> Result, DomainError>; /// Find a transaction by hash. async fn find_by_hash(&self, hash: &str) -> Result, DomainError>; diff --git a/pcidss/core/src/types.rs b/pcidss/core/src/types.rs index 1d4265a..7be56f4 100644 --- a/pcidss/core/src/types.rs +++ b/pcidss/core/src/types.rs @@ -3,18 +3,18 @@ /// `TransactionType` is an enum for the type of transaction. #[derive(Debug, Clone, PartialEq)] pub enum TransactionType { - /// Add to account balance. - Debit, - /// Deduct from account balance. - Credit, + /// Add to account balance. + Debit, + /// Deduct from account balance. + Credit, } #[allow(clippy::from_over_into)] impl Into for TransactionType { - fn into(self) -> u32 { - match self { - TransactionType::Debit => 0, - TransactionType::Credit => 1, - } - } + fn into(self) -> u32 { + match self { + TransactionType::Debit => 0, + TransactionType::Credit => 1, + } + } } diff --git a/pcidss/core/src/utils.rs b/pcidss/core/src/utils.rs index 5e8b904..db385f6 100644 --- a/pcidss/core/src/utils.rs +++ b/pcidss/core/src/utils.rs @@ -1,28 +1,30 @@ -use std::cell::RefCell; -use std::sync::{ - atomic::{AtomicUsize, Ordering}, - Arc, +use std::{ + cell::RefCell, + sync::{ + atomic::{AtomicUsize, Ordering}, + Arc, + }, }; /// Blocks current thread until ctrl-c is received pub async fn block_until_sigint() { - let (ctrlc_send, ctrlc_oneshot) = futures::channel::oneshot::channel(); - let ctrlc_send_c = RefCell::new(Some(ctrlc_send)); + let (ctrlc_send, ctrlc_oneshot) = futures::channel::oneshot::channel(); + let ctrlc_send_c = RefCell::new(Some(ctrlc_send)); - let running = Arc::new(AtomicUsize::new(0)); - ctrlc::set_handler(move || { - let prev = running.fetch_add(1, Ordering::SeqCst); - if prev == 0 { - println!("Got interrupt, shutting down..."); - // Send sig int in channel to blocking task - if let Some(ctrlc_send) = ctrlc_send_c.try_borrow_mut().unwrap().take() { - ctrlc_send.send(()).expect("Error sending ctrl-c message"); - } - } else { - std::process::exit(0); - } - }) - .expect("Error setting Ctrl-C handler"); + let running = Arc::new(AtomicUsize::new(0)); + ctrlc::set_handler(move || { + let prev = running.fetch_add(1, Ordering::SeqCst); + if prev == 0 { + println!("Got interrupt, shutting down..."); + // Send sig int in channel to blocking task + if let Some(ctrlc_send) = ctrlc_send_c.try_borrow_mut().unwrap().take() { + ctrlc_send.send(()).expect("Error sending ctrl-c message"); + } + } else { + std::process::exit(0); + } + }) + .expect("Error setting Ctrl-C handler"); - ctrlc_oneshot.await.unwrap(); + ctrlc_oneshot.await.unwrap(); }