From 9d03731a793585905ac6543aec4ee17ffd1e0fb5 Mon Sep 17 00:00:00 2001 From: John Vandenberg Date: Thu, 24 Jul 2025 06:29:01 +0800 Subject: [PATCH] Fix clippy lint needless_doctest_main --- src/clients/blocking_client.rs | 60 ++++++++++++++-------------------- 1 file changed, 25 insertions(+), 35 deletions(-) diff --git a/src/clients/blocking_client.rs b/src/clients/blocking_client.rs index 0519400..27532c4 100644 --- a/src/clients/blocking_client.rs +++ b/src/clients/blocking_client.rs @@ -62,13 +62,11 @@ impl BlockingClient { /// ```no_run /// use mini_redis::clients::BlockingClient; /// - /// fn main() { - /// let client = match BlockingClient::connect("localhost:6379") { - /// Ok(client) => client, - /// Err(_) => panic!("failed to establish connection"), - /// }; + /// let client = match BlockingClient::connect("localhost:6379") { + /// Ok(client) => client, + /// Err(_) => panic!("failed to establish connection"), + /// }; /// # drop(client); - /// } /// ``` pub fn connect(addr: T) -> crate::Result { let rt = tokio::runtime::Builder::new_current_thread() @@ -91,12 +89,10 @@ impl BlockingClient { /// ```no_run /// use mini_redis::clients::BlockingClient; /// - /// fn main() { - /// let mut client = BlockingClient::connect("localhost:6379").unwrap(); + /// let mut client = BlockingClient::connect("localhost:6379").unwrap(); /// - /// let val = client.get("foo").unwrap(); - /// println!("Got = {:?}", val); - /// } + /// let val = client.get("foo").unwrap(); + /// println!("Got = {val:?}"); /// ``` pub fn get(&mut self, key: &str) -> crate::Result> { self.rt.block_on(self.inner.get(key)) @@ -117,15 +113,13 @@ impl BlockingClient { /// ```no_run /// use mini_redis::clients::BlockingClient; /// - /// fn main() { - /// let mut client = BlockingClient::connect("localhost:6379").unwrap(); + /// let mut client = BlockingClient::connect("localhost:6379").unwrap(); /// - /// client.set("foo", "bar".into()).unwrap(); + /// client.set("foo", "bar".into()).unwrap(); /// - /// // Getting the value immediately works - /// let val = client.get("foo").unwrap().unwrap(); - /// assert_eq!(val, "bar"); - /// } + /// // Getting the value immediately works + /// let val = client.get("foo").unwrap().unwrap(); + /// assert_eq!(val, "bar"); /// ``` pub fn set(&mut self, key: &str, value: Bytes) -> crate::Result<()> { self.rt.block_on(self.inner.set(key, value)) @@ -153,22 +147,20 @@ impl BlockingClient { /// use std::thread; /// use std::time::Duration; /// - /// fn main() { - /// let ttl = Duration::from_millis(500); - /// let mut client = BlockingClient::connect("localhost:6379").unwrap(); + /// let ttl = Duration::from_millis(500); + /// let mut client = BlockingClient::connect("localhost:6379").unwrap(); /// - /// client.set_expires("foo", "bar".into(), ttl).unwrap(); + /// client.set_expires("foo", "bar".into(), ttl).unwrap(); /// - /// // Getting the value immediately works - /// let val = client.get("foo").unwrap().unwrap(); - /// assert_eq!(val, "bar"); + /// // Getting the value immediately works + /// let val = client.get("foo").unwrap().unwrap(); + /// assert_eq!(val, "bar"); /// - /// // Wait for the TTL to expire - /// thread::sleep(ttl); + /// // Wait for the TTL to expire + /// thread::sleep(ttl); /// - /// let val = client.get("foo").unwrap(); - /// assert!(val.is_some()); - /// } + /// let val = client.get("foo").unwrap(); + /// assert!(val.is_none()); /// ``` pub fn set_expires( &mut self, @@ -193,12 +185,10 @@ impl BlockingClient { /// ```no_run /// use mini_redis::clients::BlockingClient; /// - /// fn main() { - /// let mut client = BlockingClient::connect("localhost:6379").unwrap(); + /// let mut client = BlockingClient::connect("localhost:6379").unwrap(); /// - /// let val = client.publish("foo", "bar".into()).unwrap(); - /// println!("Got = {:?}", val); - /// } + /// let val = client.publish("foo", "bar".into()).unwrap(); + /// println!("Got = {val:?}"); /// ``` pub fn publish(&mut self, channel: &str, message: Bytes) -> crate::Result { self.rt.block_on(self.inner.publish(channel, message))