From 1db847cfbbe354f82fc98efbbcd7227ce4152dda Mon Sep 17 00:00:00 2001 From: Nick Pillitteri Date: Sat, 30 Dec 2023 22:04:04 -0500 Subject: [PATCH] Make key type for `Memcached::get` more generic --- mtop-client/src/core.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/mtop-client/src/core.rs b/mtop-client/src/core.rs index 5adad2a..25a6bc6 100644 --- a/mtop-client/src/core.rs +++ b/mtop-client/src/core.rs @@ -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, MtopError> { + pub async fn get(&mut self, keys: I) -> Result, MtopError> + where + I: IntoIterator, + K: Into, + { + let keys: Vec = 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 { @@ -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 = Vec::new(); + let res = client.get(keys).await; assert!(res.is_err()); let err = res.unwrap_err();