Skip to content

Commit

Permalink
Make key type for Memcached::get more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
56quarters committed Dec 31, 2023
1 parent 38ec17b commit 1db847c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions mtop-client/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,16 +832,22 @@ impl Memcached {

/// Get a map of the requested keys and their corresponding `Value` in the cache
/// including the key, flags, and data.
pub async fn get(&mut self, keys: &[String]) -> Result<HashMap<String, Value>, MtopError> {
pub async fn get<I, K>(&mut self, keys: I) -> Result<HashMap<String, Value>, MtopError>
where
I: IntoIterator<Item = K>,
K: Into<String>,
{
let keys: Vec<String> = keys.into_iter().map(|k| k.into()).collect();

if keys.is_empty() {
return Err(MtopError::internal("missing required keys"));
}

if !validate_keys(keys) {
if !validate_keys(&keys) {
return Err(MtopError::internal("invalid keys"));
}

self.send(Command::Gets(keys)).await?;
self.send(Command::Gets(&keys)).await?;
let mut out = HashMap::with_capacity(keys.len());

loop {
Expand Down Expand Up @@ -1146,7 +1152,8 @@ mod test {
#[tokio::test]
async fn test_get_no_key() {
let mut client = client!();
let res = client.get(&[]).await;
let keys: Vec<String> = Vec::new();
let res = client.get(keys).await;

assert!(res.is_err());
let err = res.unwrap_err();
Expand Down

0 comments on commit 1db847c

Please sign in to comment.