diff --git a/agency_client/src/agency_client.rs b/agency_client/src/agency_client.rs index 8cba291f05..e96e323ec9 100644 --- a/agency_client/src/agency_client.rs +++ b/agency_client/src/agency_client.rs @@ -20,8 +20,7 @@ pub struct AgencyClient { pub fn validate_mandotory_config_val(val: &str, err: AgencyClientErrorKind, closure: F) -> AgencyClientResult<()> where F: Fn(&str) -> Result { - closure(val) - .or_else(|_| Err(AgencyClientError::from(err)))?; + closure(val).map_err(|_| AgencyClientError::from(err))?; Ok(()) } diff --git a/agency_client/src/api/downloaded_message.rs b/agency_client/src/api/downloaded_message.rs index 3130d91505..cd572e79e0 100644 --- a/agency_client/src/api/downloaded_message.rs +++ b/agency_client/src/api/downloaded_message.rs @@ -62,6 +62,6 @@ impl DownloadedMessageEncrypted { } async fn _auth_decrypt_v3_message(&self, wallet_handle: WalletHandle, expected_sender_vk: &str) -> AgencyClientResult { - EncryptionEnvelope::auth_unpack(wallet_handle, self.payload()?, &expected_sender_vk).await + EncryptionEnvelope::auth_unpack(wallet_handle, self.payload()?, expected_sender_vk).await } } diff --git a/agency_client/src/api/messaging.rs b/agency_client/src/api/messaging.rs index f65380ad62..57a0a0cbd3 100644 --- a/agency_client/src/api/messaging.rs +++ b/agency_client/src/api/messaging.rs @@ -45,7 +45,7 @@ impl AgencyClient { .build() ); - let data = self.prepare_message_for_connection_agent(vec![message], &to_pw_vk, &agent_did, &agent_vk).await?; + let data = self.prepare_message_for_connection_agent(vec![message], to_pw_vk, agent_did, agent_vk).await?; let response = self.post_to_agency(&data).await?; let mut response = self.parse_response_from_agency(&response).await?; diff --git a/agency_client/src/api/onboarding.rs b/agency_client/src/api/onboarding.rs index 4d1e4d5b9d..fa7458684d 100644 --- a/agency_client/src/api/onboarding.rs +++ b/agency_client/src/api/onboarding.rs @@ -14,7 +14,7 @@ impl AgencyClient { trace!("connect >>> my_did: {}, my_vk: {}, agency_did: {}", my_did, my_vk, agency_did); let message = Client2AgencyMessage::Connect(Connect::build(my_did, my_vk)); - let mut response = self.send_message_to_agency(&message, agency_did, &agency_vk).await?; + let mut response = self.send_message_to_agency(&message, agency_did, agency_vk).await?; let ConnectResponse { from_vk: agency_pw_vk, from_did: agency_pw_did, .. } = match response.remove(0) { @@ -34,7 +34,7 @@ impl AgencyClient { let message = Client2AgencyMessage::SignUp(SignUp::build()); AgencyMockDecrypted::set_next_decrypted_response(test_constants::REGISTER_RESPONSE_DECRYPTED); - let mut response = self.send_message_to_agency(&message, &agency_pw_did, &agency_pw_vk).await?; + let mut response = self.send_message_to_agency(&message, agency_pw_did, agency_pw_vk).await?; let _response: SignUpResponse = match response.remove(0) { @@ -47,7 +47,7 @@ impl AgencyClient { async fn _create_agent(&self, agency_pw_did: &str, agency_pw_vk: &str) -> AgencyClientResult { let message = Client2AgencyMessage::CreateAgent(CreateAgent::build()); AgencyMockDecrypted::set_next_decrypted_response(test_constants::AGENT_CREATED_DECRYPTED); - let mut response = self.send_message_to_agency(&message, &agency_pw_did, &agency_pw_vk).await?; + let mut response = self.send_message_to_agency(&message, agency_pw_did, agency_pw_vk).await?; let response: CreateAgentResponse = match response.remove(0) { diff --git a/agency_client/src/httpclient.rs b/agency_client/src/httpclient.rs index 05aa9d1ba6..61bcaca360 100644 --- a/agency_client/src/httpclient.rs +++ b/agency_client/src/httpclient.rs @@ -51,7 +51,7 @@ pub async fn post_message(body_content: &Vec, url: &str) -> AgencyClientResu .send() .await .map_err(|err| { - AgencyClientError::from_msg(AgencyClientErrorKind::PostMessageFailed, format!("HTTP Client could not connect with {}, err: {}", url, err.to_string())) + AgencyClientError::from_msg(AgencyClientErrorKind::PostMessageFailed, format!("HTTP Client could not connect with {}, err: {}", url, err)) })?; let content_length = response.content_length(); @@ -61,11 +61,11 @@ pub async fn post_message(body_content: &Vec, url: &str) -> AgencyClientResu if response_status.is_success() { Ok(payload.into_bytes()) } else { - Err(AgencyClientError::from_msg(AgencyClientErrorKind::PostMessageFailed, format!("POST {} failed due to non-success HTTP status: {}, response body: {}", url, response_status.to_string(), payload))) + Err(AgencyClientError::from_msg(AgencyClientErrorKind::PostMessageFailed, format!("POST {} failed due to non-success HTTP status: {}, response body: {}", url, response_status, payload))) } } Err(error) => { - Err(AgencyClientError::from_msg(AgencyClientErrorKind::PostMessageFailed, format!("POST {} failed because response could not be decoded as utf-8, HTTP status: {}, content-length header: {:?}, error: {:?}", url, response_status.to_string(), content_length, error))) + Err(AgencyClientError::from_msg(AgencyClientErrorKind::PostMessageFailed, format!("POST {} failed because response could not be decoded as utf-8, HTTP status: {}, content-length header: {:?}, error: {:?}", url, response_status, content_length, error))) } } } diff --git a/agency_client/src/internal/messaging.rs b/agency_client/src/internal/messaging.rs index 6194b3becb..cc043c3d6d 100644 --- a/agency_client/src/internal/messaging.rs +++ b/agency_client/src/internal/messaging.rs @@ -101,7 +101,7 @@ impl AgencyClient { pub async fn send_message_to_agency(&self, message: &Client2AgencyMessage, did: &str, verkey: &str) -> AgencyClientResult> { trace!("send_message_to_agency >>> message: ..., did: {}", did); - let data = self.prepare_message_for_agency(message, &did, verkey).await?; + let data = self.prepare_message_for_agency(message, did, verkey).await?; let response = self.post_to_agency(&data).await?; self.parse_response_from_agency(&response).await } diff --git a/agency_client/src/lib.rs b/agency_client/src/lib.rs index 921539c9c4..b3df8aad21 100644 --- a/agency_client/src/lib.rs +++ b/agency_client/src/lib.rs @@ -51,7 +51,7 @@ impl std::string::ToString for MessageStatusCode { impl Serialize for MessageStatusCode { fn serialize(&self, serializer: S) -> Result where S: Serializer { let value = self.to_string(); - Value::String(value.to_string()).serialize(serializer) + Value::String(value).serialize(serializer) } } diff --git a/agency_client/src/messages/update_message.rs b/agency_client/src/messages/update_message.rs index b1a163058c..d0653c6649 100644 --- a/agency_client/src/messages/update_message.rs +++ b/agency_client/src/messages/update_message.rs @@ -49,7 +49,7 @@ impl UpdateMessageStatusByConnectionsBuilder { } pub fn status_code(&mut self, code: MessageStatusCode) -> AgencyClientResult<&mut Self> { - self.status_code = Some(code.clone()); + self.status_code = Some(code); Ok(self) } diff --git a/agency_client/src/testing/mocking.rs b/agency_client/src/testing/mocking.rs index 2f2db2892c..dadc061aca 100644 --- a/agency_client/src/testing/mocking.rs +++ b/agency_client/src/testing/mocking.rs @@ -23,7 +23,7 @@ impl HttpClientMockResponse { } pub fn has_response() -> bool { - HTTPCLIENT_MOCK_RESPONSES.lock().unwrap().responses.len() > 0 + !HTTPCLIENT_MOCK_RESPONSES.lock().unwrap().responses.is_empty() } pub fn get_response() -> AgencyClientResult> { @@ -77,7 +77,7 @@ impl AgencyMockDecrypted { } pub fn has_decrypted_mock_responses() -> bool { - AGENCY_MOCK_DECRYPTED_RESPONSES.lock().unwrap().responses.len() > 0 + !AGENCY_MOCK_DECRYPTED_RESPONSES.lock().unwrap().responses.is_empty() } pub fn set_next_decrypted_message(message: &str) { @@ -92,7 +92,7 @@ impl AgencyMockDecrypted { } pub fn has_decrypted_mock_messages() -> bool { - AGENCY_MOCK_DECRYPTED_MESSAGES.lock().unwrap().messages.len() > 0 + !AGENCY_MOCK_DECRYPTED_MESSAGES.lock().unwrap().messages.is_empty() } pub fn clear_mocks() { diff --git a/agency_client/src/utils/error_utils.rs b/agency_client/src/utils/error_utils.rs index 2f675184c5..d72d8481c8 100644 --- a/agency_client/src/utils/error_utils.rs +++ b/agency_client/src/utils/error_utils.rs @@ -30,6 +30,6 @@ pub fn kind_to_error_message(kind: &AgencyClientErrorKind) -> String { AgencyClientErrorKind::InvalidHttpResponse => "Invalid HTTP response.".into(), AgencyClientErrorKind::CreateAgent => "Failed to create agency client".into(), AgencyClientErrorKind::UnknownLibndyError => "Unknown libindy error".into(), - AgencyClientErrorKind::LibndyError(e) => format!("Libindy error with code {}", e).into(), + AgencyClientErrorKind::LibndyError(e) => format!("Libindy error with code {}", e), } }