From b3ac027b00a1b986302e909c9bb6e2534627944e Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Thu, 25 Aug 2022 21:46:06 +0100 Subject: [PATCH] remove needless pass by value --- examples/sweeping.rs | 2 +- src/apis/payments/model.rs | 2 +- src/authenticator.rs | 8 +++----- src/lib.rs | 1 + tests/common/mock_server/routes.rs | 4 ++-- tests/integration_tests/payments.rs | 2 +- 6 files changed, 9 insertions(+), 10 deletions(-) diff --git a/examples/sweeping.rs b/examples/sweeping.rs index 6a0cb26..6e48ada 100644 --- a/examples/sweeping.rs +++ b/examples/sweeping.rs @@ -105,7 +105,7 @@ async fn run() -> anyhow::Result<()> { &merchant_account.id, &SetupSweepingRequest { max_amount_in_minor: amount, - currency: merchant_account.currency.clone(), + currency: merchant_account.currency, frequency: frequency.clone(), }, ) diff --git a/src/apis/payments/model.rs b/src/apis/payments/model.rs index 997db67..7a8e603 100644 --- a/src/apis/payments/model.rs +++ b/src/apis/payments/model.rs @@ -123,7 +123,7 @@ pub enum PaymentStatus { }, } -#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq, Hash)] +#[derive(Serialize, Deserialize, Debug, Clone, Copy, Eq, PartialEq, Hash)] #[serde(rename_all = "UPPERCASE")] pub enum Currency { Gbp, diff --git a/src/authenticator.rs b/src/authenticator.rs index cd7eec4..962f295 100644 --- a/src/authenticator.rs +++ b/src/authenticator.rs @@ -17,10 +17,11 @@ pub struct Authenticator { impl Authenticator { /// Starts a new authenticator with the given initial credentials. pub fn new(client: ClientWithMiddleware, auth_url: Url, credentials: Credentials) -> Self { + let client_id = credentials.client_id().to_string(); let state = AuthenticatorState { client, auth_url, - credentials: credentials.clone(), + credentials, access_token: None, }; @@ -36,10 +37,7 @@ impl Authenticator { process_loop(state, rx).await; }); - Self { - tx, - client_id: credentials.client_id().into(), - } + Self { tx, client_id } } /// Returns the current access token used for authentication against the TrueLayer APIs. diff --git a/src/lib.rs b/src/lib.rs index ea3a911..a2032c0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -137,6 +137,7 @@ //! ``` #![deny(missing_debug_implementations)] +#![warn(clippy::needless_pass_by_value)] #![forbid(unsafe_code)] pub mod apis; diff --git a/tests/common/mock_server/routes.rs b/tests/common/mock_server/routes.rs index 6bf6e52..033837f 100644 --- a/tests/common/mock_server/routes.rs +++ b/tests/common/mock_server/routes.rs @@ -75,7 +75,7 @@ pub(super) async fn create_payment( Payment { id: id.clone(), amount_in_minor: create_payment_request.amount_in_minor, - currency: create_payment_request.currency.clone(), + currency: create_payment_request.currency, user: user.clone(), payment_method: create_payment_request.payment_method.clone(), created_at: Utc::now(), @@ -544,7 +544,7 @@ pub(super) async fn create_payout( id: payout_id.clone(), merchant_account_id: request.merchant_account_id.clone(), amount_in_minor: request.amount_in_minor, - currency: request.currency.clone(), + currency: request.currency, beneficiary: request.beneficiary.clone(), created_at: Utc::now(), status: PayoutStatus::Pending, diff --git a/tests/integration_tests/payments.rs b/tests/integration_tests/payments.rs index 53d3dfb..5803982 100644 --- a/tests/integration_tests/payments.rs +++ b/tests/integration_tests/payments.rs @@ -179,7 +179,7 @@ impl CreatePaymentScenario { // Create a payment let create_payment_request = CreatePaymentRequest { amount_in_minor: 1, - currency: self.currency.clone(), + currency: self.currency, payment_method: PaymentMethod::BankTransfer { provider_selection, beneficiary: match self.beneficiary {