mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 09:07:09 +08:00
chore: enable clippy::trivially_copy_pass_by_ref lint and address it (#6724)
This commit is contained in:
@ -599,13 +599,13 @@ pub enum Currency {
|
||||
|
||||
impl Currency {
|
||||
/// Convert the amount to its base denomination based on Currency and return String
|
||||
pub fn to_currency_base_unit(&self, amount: i64) -> Result<String, TryFromIntError> {
|
||||
pub fn to_currency_base_unit(self, amount: i64) -> Result<String, TryFromIntError> {
|
||||
let amount_f64 = self.to_currency_base_unit_asf64(amount)?;
|
||||
Ok(format!("{amount_f64:.2}"))
|
||||
}
|
||||
|
||||
/// Convert the amount to its base denomination based on Currency and return f64
|
||||
pub fn to_currency_base_unit_asf64(&self, amount: i64) -> Result<f64, TryFromIntError> {
|
||||
pub fn to_currency_base_unit_asf64(self, amount: i64) -> Result<f64, TryFromIntError> {
|
||||
let amount_f64: f64 = u32::try_from(amount)?.into();
|
||||
let amount = if self.is_zero_decimal_currency() {
|
||||
amount_f64
|
||||
@ -618,7 +618,7 @@ impl Currency {
|
||||
}
|
||||
|
||||
///Convert the higher decimal amount to its base absolute units
|
||||
pub fn to_currency_lower_unit(&self, amount: String) -> Result<String, ParseFloatError> {
|
||||
pub fn to_currency_lower_unit(self, amount: String) -> Result<String, ParseFloatError> {
|
||||
let amount_f64 = amount.parse::<f64>()?;
|
||||
let amount_string = if self.is_zero_decimal_currency() {
|
||||
amount_f64
|
||||
@ -634,7 +634,7 @@ impl Currency {
|
||||
/// Paypal Connector accepts Zero and Two decimal currency but not three decimal and it should be updated as required for 3 decimal currencies.
|
||||
/// Paypal Ref - https://developer.paypal.com/docs/reports/reference/paypal-supported-currencies/
|
||||
pub fn to_currency_base_unit_with_zero_decimal_check(
|
||||
&self,
|
||||
self,
|
||||
amount: i64,
|
||||
) -> Result<String, TryFromIntError> {
|
||||
let amount_f64 = self.to_currency_base_unit_asf64(amount)?;
|
||||
@ -645,8 +645,8 @@ impl Currency {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn iso_4217(&self) -> &'static str {
|
||||
match *self {
|
||||
pub fn iso_4217(self) -> &'static str {
|
||||
match self {
|
||||
Self::AED => "784",
|
||||
Self::AFN => "971",
|
||||
Self::ALL => "008",
|
||||
@ -1301,7 +1301,7 @@ pub enum IntentStatus {
|
||||
|
||||
impl IntentStatus {
|
||||
/// Indicates whether the syncing with the connector should be allowed or not
|
||||
pub fn should_force_sync_with_connector(&self) -> bool {
|
||||
pub fn should_force_sync_with_connector(self) -> bool {
|
||||
match self {
|
||||
// Confirm has not happened yet
|
||||
Self::RequiresConfirmation
|
||||
@ -2495,7 +2495,7 @@ pub enum ClientPlatform {
|
||||
}
|
||||
|
||||
impl PaymentSource {
|
||||
pub fn is_for_internal_use_only(&self) -> bool {
|
||||
pub fn is_for_internal_use_only(self) -> bool {
|
||||
match self {
|
||||
Self::Dashboard | Self::Sdk | Self::MerchantServer | Self::Postman => false,
|
||||
Self::Webhook | Self::ExternalAuthenticator => true,
|
||||
@ -2590,7 +2590,7 @@ pub enum AuthenticationConnectors {
|
||||
}
|
||||
|
||||
impl AuthenticationConnectors {
|
||||
pub fn is_separate_version_call_required(&self) -> bool {
|
||||
pub fn is_separate_version_call_required(self) -> bool {
|
||||
match self {
|
||||
Self::Threedsecureio | Self::Netcetera => false,
|
||||
Self::Gpayments => true,
|
||||
@ -2624,15 +2624,15 @@ pub enum AuthenticationStatus {
|
||||
}
|
||||
|
||||
impl AuthenticationStatus {
|
||||
pub fn is_terminal_status(&self) -> bool {
|
||||
pub fn is_terminal_status(self) -> bool {
|
||||
match self {
|
||||
Self::Started | Self::Pending => false,
|
||||
Self::Success | Self::Failed => true,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_failed(&self) -> bool {
|
||||
self == &Self::Failed
|
||||
pub fn is_failed(self) -> bool {
|
||||
self == Self::Failed
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -522,7 +522,7 @@ impl Country {
|
||||
CountryAlpha2::ZW => Self::Zimbabwe,
|
||||
}
|
||||
}
|
||||
pub const fn to_alpha2(&self) -> CountryAlpha2 {
|
||||
pub const fn to_alpha2(self) -> CountryAlpha2 {
|
||||
match self {
|
||||
Self::Afghanistan => CountryAlpha2::AF,
|
||||
Self::AlandIslands => CountryAlpha2::AX,
|
||||
@ -1028,7 +1028,7 @@ impl Country {
|
||||
CountryAlpha3::ZWE => Self::Zimbabwe,
|
||||
}
|
||||
}
|
||||
pub const fn to_alpha3(&self) -> CountryAlpha3 {
|
||||
pub const fn to_alpha3(self) -> CountryAlpha3 {
|
||||
match self {
|
||||
Self::Afghanistan => CountryAlpha3::AFG,
|
||||
Self::AlandIslands => CountryAlpha3::ALA,
|
||||
@ -1535,7 +1535,7 @@ impl Country {
|
||||
_ => Err(NumericCountryCodeParseError),
|
||||
}
|
||||
}
|
||||
pub const fn to_numeric(&self) -> u32 {
|
||||
pub const fn to_numeric(self) -> u32 {
|
||||
match self {
|
||||
Self::Afghanistan => 4,
|
||||
Self::AlandIslands => 248,
|
||||
@ -1905,6 +1905,8 @@ mod custom_serde {
|
||||
|
||||
use super::*;
|
||||
|
||||
// `serde::Serialize` implementation needs the function to accept `&Country`
|
||||
#[allow(clippy::trivially_copy_pass_by_ref)]
|
||||
pub fn serialize<S>(code: &Country, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
@ -1937,6 +1939,8 @@ mod custom_serde {
|
||||
|
||||
use super::*;
|
||||
|
||||
// `serde::Serialize` implementation needs the function to accept `&Country`
|
||||
#[allow(clippy::trivially_copy_pass_by_ref)]
|
||||
pub fn serialize<S>(code: &Country, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
@ -1969,6 +1973,8 @@ mod custom_serde {
|
||||
|
||||
use super::*;
|
||||
|
||||
// `serde::Serialize` implementation needs the function to accept `&Country`
|
||||
#[allow(clippy::trivially_copy_pass_by_ref)]
|
||||
pub fn serialize<S>(code: &Country, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
|
||||
Reference in New Issue
Block a user