Fix map_entry lint
This change fixes a lint introduced with the Rust 1.53.0 release. The
lint warns of using `HashMap::contains` followed by an insert over using
`HashMap::entry`. The latter is considered more efficient.
See
for more details.
//! A memory-backed implementation of the [UserProfileStore]
-use std::collections::HashMap;
+use std::collections::{hash_map::Entry, HashMap};
use std::sync::{Arc, Mutex};
use crate::error::{InternalError, InvalidArgumentError, InvalidStateError};
@@ -50,8 +50,9 @@ impl UserProfileStore for MemoryUserProfileStore {
"Cannot access user profile store: mutex lock poisoned".to_string(),
))
})?;
- if inner.contains_key(&profile.user_id) {
- let new_profile = ProfileBuilder::default()
+ if let Entry::Occupied(mut entry) = inner.entry(profile.user_id.clone()) {
+ entry.insert(
+ ProfileBuilder::default()
.with_user_id(profile.user_id.clone())
.with_name(profile.name)
.with_given_name(profile.given_name)
@@ -62,8 +63,8 @@ impl UserProfileStore for MemoryUserProfileStore {
UserProfileStoreError::Internal(InternalError::with_message(
"Failed to build profile with updated details".to_string(),
))
- })?;
- inner.insert(profile.user_id, new_profile);
+ })?,
+ );
Ok(())
} else {
Err(UserProfileStoreError::InvalidArgument(
