Skip to content

Commit

Permalink
refactor: refactor create_list_wrapper macro
Browse files Browse the repository at this point in the history
  • Loading branch information
hrithikesh026 committed Dec 19, 2024
1 parent f6251f4 commit 07cc398
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 26 deletions.
30 changes: 15 additions & 15 deletions crates/common_utils/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,27 +385,27 @@ macro_rules! create_list_wrapper {
pub fn new(list: Vec<$type_name>) -> Self {
Self(list)
}
pub fn push(&mut self, item: $type_name) {
self.0.push(item)
}
pub fn len(&self) -> usize {
self.0.len()
}
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
pub fn with_capacity(size: usize) -> Self {
Self(Vec::with_capacity(size))
}
pub fn iter(&self) -> std::slice::Iter<'_, $type_name> {
self.0.iter()
}
$($function_def)*
}
impl Iterator for $wrapper_name {
impl std::ops::Deref for $wrapper_name {
type Target = Vec<$type_name>;
fn deref(&self) -> &<Self as std::ops::Deref>::Target {
&self.0
}
}
impl std::ops::DerefMut for $wrapper_name {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl IntoIterator for $wrapper_name {
type Item = $type_name;
fn next(&mut self) -> Option<Self::Item> {
self.0.pop()
type IntoIter = std::vec::IntoIter<$type_name>;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,15 +563,6 @@ common_utils::create_list_wrapper!(
MerchantConnectorAccounts,
MerchantConnectorAccount,
impl_functions: {
pub fn into_inner(self) -> Vec<MerchantConnectorAccount> {
self.0
}
pub fn retain<F>(&mut self, f: F)
where
F: FnMut(&MerchantConnectorAccount) -> bool
{
self.0.retain(f)
}
fn filter_and_map<'a, T>(
&'a self,
filter: impl Fn(&'a MerchantConnectorAccount) -> bool,
Expand Down
3 changes: 1 addition & 2 deletions crates/router/src/core/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1789,10 +1789,9 @@ impl<'a> PMAuthConfigValidation<'a> {
.change_context(errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
id: self.merchant_id.get_string_repr().to_owned(),
})?;

for conn_choice in config.enabled_payment_methods {
let pm_auth_mca = all_mcas
.clone()
.iter()
.find(|mca| mca.get_id() == conn_choice.mca_id)
.ok_or(errors::ApiErrorResponse::GenericNotFoundError {
message: "payment method auth connector account not found".to_string(),
Expand Down

0 comments on commit 07cc398

Please sign in to comment.