Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-implement ConnectionLike for DerefMut #567

Merged
merged 1 commit into from May 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/connection.rs
@@ -1,6 +1,7 @@
use std::fmt;
use std::io::{self, Write};
use std::net::{self, TcpStream, ToSocketAddrs};
use std::ops::{Deref, DerefMut};
use std::path::PathBuf;
use std::str::{from_utf8, FromStr};
use std::time::Duration;
Expand Down Expand Up @@ -886,6 +887,45 @@ impl ConnectionLike for Connection {
}
}

impl<C, T> ConnectionLike for T
where
C: ConnectionLike,
T: DerefMut<Target = C>,
{
fn req_packed_command(&mut self, cmd: &[u8]) -> RedisResult<Value> {
self.deref_mut().req_packed_command(cmd)
}

fn req_packed_commands(
&mut self,
cmd: &[u8],
offset: usize,
count: usize,
) -> RedisResult<Vec<Value>> {
self.deref_mut().req_packed_commands(cmd, offset, count)
}

fn req_command(&mut self, cmd: &Cmd) -> RedisResult<Value> {
self.deref_mut().req_command(cmd)
}

fn get_db(&self) -> i64 {
self.deref().get_db()
}

fn supports_pipelining(&self) -> bool {
self.deref().supports_pipelining()
}

fn check_connection(&mut self) -> bool {
self.deref_mut().check_connection()
}

fn is_open(&self) -> bool {
self.deref().is_open()
}
}

/// The pubsub object provides convenient access to the redis pubsub
/// system. Once created you can subscribe and unsubscribe from channels
/// and listen in on messages.
Expand Down