Skip to content

Commit

Permalink
chore: apply rust 2018 idioms lint
Browse files Browse the repository at this point in the history
  • Loading branch information
robjtede committed Aug 27, 2023
1 parent 11b7306 commit 840a37b
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 33 deletions.
2 changes: 2 additions & 0 deletions redis-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
//! assert_eq!(result, true);
//! ```

#![deny(rust_2018_idioms, nonstandard_style, future_incompatible)]

use std::collections::VecDeque;
use std::iter::FromIterator;
use std::sync::{Arc, Mutex};
Expand Down
16 changes: 8 additions & 8 deletions redis/src/aio/async_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,22 @@ where
{
fn poll_write(
self: Pin<&mut Self>,
cx: &mut core::task::Context,
cx: &mut core::task::Context<'_>,
buf: &[u8],
) -> std::task::Poll<Result<usize, tokio::io::Error>> {
async_std::io::Write::poll_write(self.project().inner, cx, buf)
}

fn poll_flush(
self: Pin<&mut Self>,
cx: &mut core::task::Context,
cx: &mut core::task::Context<'_>,
) -> std::task::Poll<Result<(), tokio::io::Error>> {
async_std::io::Write::poll_flush(self.project().inner, cx)
}

fn poll_shutdown(
self: Pin<&mut Self>,
cx: &mut core::task::Context,
cx: &mut core::task::Context<'_>,
) -> std::task::Poll<Result<(), tokio::io::Error>> {
async_std::io::Write::poll_close(self.project().inner, cx)
}
Expand All @@ -93,7 +93,7 @@ where
{
fn poll_read(
self: Pin<&mut Self>,
cx: &mut core::task::Context,
cx: &mut core::task::Context<'_>,
buf: &mut ReadBuf<'_>,
) -> std::task::Poll<Result<(), tokio::io::Error>> {
let n = ready!(async_std::io::Read::poll_read(
Expand Down Expand Up @@ -124,7 +124,7 @@ pub enum AsyncStd {
impl AsyncWrite for AsyncStd {
fn poll_write(
mut self: Pin<&mut Self>,
cx: &mut task::Context,
cx: &mut task::Context<'_>,
buf: &[u8],
) -> Poll<io::Result<usize>> {
match &mut *self {
Expand All @@ -139,7 +139,7 @@ impl AsyncWrite for AsyncStd {
}
}

fn poll_flush(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll<io::Result<()>> {
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<io::Result<()>> {
match &mut *self {
AsyncStd::Tcp(r) => Pin::new(r).poll_flush(cx),
#[cfg(any(
Expand All @@ -152,7 +152,7 @@ impl AsyncWrite for AsyncStd {
}
}

fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll<io::Result<()>> {
fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<io::Result<()>> {
match &mut *self {
AsyncStd::Tcp(r) => Pin::new(r).poll_shutdown(cx),
#[cfg(any(
Expand All @@ -169,7 +169,7 @@ impl AsyncWrite for AsyncStd {
impl AsyncRead for AsyncStd {
fn poll_read(
mut self: Pin<&mut Self>,
cx: &mut task::Context,
cx: &mut task::Context<'_>,
buf: &mut ReadBuf<'_>,
) -> Poll<io::Result<()>> {
match &mut *self {
Expand Down
8 changes: 4 additions & 4 deletions redis/src/aio/multiplexed_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ where
}

// Read messages from the stream and send them back to the caller
fn poll_read(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll<Result<(), ()>> {
fn poll_read(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Result<(), ()>> {
loop {
// No need to try reading a message if there is no message in flight
if self.in_flight.is_empty() {
Expand Down Expand Up @@ -168,7 +168,7 @@ where
// Retrieve incoming messages and write them to the sink
fn poll_ready(
mut self: Pin<&mut Self>,
cx: &mut task::Context,
cx: &mut task::Context<'_>,
) -> Poll<Result<(), Self::Error>> {
match ready!(self.as_mut().project().sink_stream.poll_ready(cx)) {
Ok(()) => Ok(()).into(),
Expand Down Expand Up @@ -217,7 +217,7 @@ where

fn poll_flush(
mut self: Pin<&mut Self>,
cx: &mut task::Context,
cx: &mut task::Context<'_>,
) -> Poll<Result<(), Self::Error>> {
ready!(self
.as_mut()
Expand All @@ -232,7 +232,7 @@ where

fn poll_close(
mut self: Pin<&mut Self>,
cx: &mut task::Context,
cx: &mut task::Context<'_>,
) -> Poll<Result<(), Self::Error>> {
// No new requests will come in after the first call to `close` but we need to complete any
// in progress requests before closing
Expand Down
8 changes: 4 additions & 4 deletions redis/src/aio/tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub(crate) enum Tokio {
impl AsyncWrite for Tokio {
fn poll_write(
mut self: Pin<&mut Self>,
cx: &mut task::Context,
cx: &mut task::Context<'_>,
buf: &[u8],
) -> Poll<io::Result<usize>> {
match &mut *self {
Expand All @@ -75,7 +75,7 @@ impl AsyncWrite for Tokio {
}
}

fn poll_flush(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll<io::Result<()>> {
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<io::Result<()>> {
match &mut *self {
Tokio::Tcp(r) => Pin::new(r).poll_flush(cx),
#[cfg(any(feature = "tokio-native-tls-comp", feature = "tokio-rustls-comp"))]
Expand All @@ -85,7 +85,7 @@ impl AsyncWrite for Tokio {
}
}

fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll<io::Result<()>> {
fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<io::Result<()>> {
match &mut *self {
Tokio::Tcp(r) => Pin::new(r).poll_shutdown(cx),
#[cfg(any(feature = "tokio-native-tls-comp", feature = "tokio-rustls-comp"))]
Expand All @@ -99,7 +99,7 @@ impl AsyncWrite for Tokio {
impl AsyncRead for Tokio {
fn poll_read(
mut self: Pin<&mut Self>,
cx: &mut task::Context,
cx: &mut task::Context<'_>,
buf: &mut ReadBuf<'_>,
) -> Poll<io::Result<()>> {
match &mut *self {
Expand Down
8 changes: 4 additions & 4 deletions redis/src/cluster_async/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ where
{
type Output = Next<I, C>;

fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll<Self::Output> {
fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
let mut this = self.as_mut().project();
if this.request.is_none() {
return Poll::Ready(Next::Done);
Expand Down Expand Up @@ -937,7 +937,7 @@ where

fn poll_ready(
mut self: Pin<&mut Self>,
cx: &mut task::Context,
cx: &mut task::Context<'_>,
) -> Poll<Result<(), Self::Error>> {
match mem::replace(&mut self.state, ConnectionState::PollComplete) {
ConnectionState::PollComplete => Poll::Ready(Ok(())),
Expand Down Expand Up @@ -980,7 +980,7 @@ where

fn poll_flush(
mut self: Pin<&mut Self>,
cx: &mut task::Context,
cx: &mut task::Context<'_>,
) -> Poll<Result<(), Self::Error>> {
trace!("poll_complete: {:?}", self.state);
loop {
Expand Down Expand Up @@ -1023,7 +1023,7 @@ where

fn poll_close(
mut self: Pin<&mut Self>,
cx: &mut task::Context,
cx: &mut task::Context<'_>,
) -> Poll<Result<(), Self::Error>> {
// Try to drive any in flight requests to completion
match self.poll_complete(cx) {
Expand Down
2 changes: 1 addition & 1 deletion redis/src/cluster_routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ impl SlotMap {
self.0.clear();
}

pub fn values(&self) -> std::collections::btree_map::Values<u16, SlotAddrs> {
pub fn values(&self) -> std::collections::btree_map::Values<'_, u16, SlotAddrs> {
self.0.values()
}

Expand Down
4 changes: 2 additions & 2 deletions redis/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ struct AsyncIterInner<'a, T: FromRedisValue + 'a> {

/// Represents the state of AsyncIter
#[cfg(feature = "aio")]
enum IterOrFuture<'a, T: FromRedisValue + 'a> {
enum IterOrFuture<'a, T: FromRedisValue> {
Iter(AsyncIterInner<'a, T>),
Future(BoxFuture<'a, (AsyncIterInner<'a, T>, Option<T>)>),
Empty,
}

/// Represents a redis iterator that can be used with async connections.
#[cfg(feature = "aio")]
pub struct AsyncIter<'a, T: FromRedisValue + 'a> {
pub struct AsyncIter<'a, T: FromRedisValue> {
inner: IterOrFuture<'a, T>,
}

Expand Down
16 changes: 8 additions & 8 deletions redis/src/commands/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,23 +172,23 @@ macro_rules! implement_commands {

/// Incrementally iterate the keys space.
#[inline]
fn scan<RV: FromRedisValue>(&mut self) -> crate::types::RedisFuture<crate::cmd::AsyncIter<'_, RV>> {
fn scan<RV: FromRedisValue>(&mut self) -> crate::types::RedisFuture<'_, crate::cmd::AsyncIter<'_, RV>> {
let mut c = cmd("SCAN");
c.cursor_arg(0);
Box::pin(async move { c.iter_async(self).await })
}

/// Incrementally iterate set elements for elements matching a pattern.
#[inline]
fn scan_match<P: ToRedisArgs, RV: FromRedisValue>(&mut self, pattern: P) -> crate::types::RedisFuture<crate::cmd::AsyncIter<'_, RV>> {
fn scan_match<P: ToRedisArgs, RV: FromRedisValue>(&mut self, pattern: P) -> crate::types::RedisFuture<'_, crate::cmd::AsyncIter<'_, RV>> {
let mut c = cmd("SCAN");
c.cursor_arg(0).arg("MATCH").arg(pattern);
Box::pin(async move { c.iter_async(self).await })
}

/// Incrementally iterate hash fields and associated values.
#[inline]
fn hscan<K: ToRedisArgs, RV: FromRedisValue>(&mut self, key: K) -> crate::types::RedisFuture<crate::cmd::AsyncIter<'_, RV>> {
fn hscan<K: ToRedisArgs, RV: FromRedisValue>(&mut self, key: K) -> crate::types::RedisFuture<'_, crate::cmd::AsyncIter<'_, RV>> {
let mut c = cmd("HSCAN");
c.arg(key).cursor_arg(0);
Box::pin(async move {c.iter_async(self).await })
Expand All @@ -198,15 +198,15 @@ macro_rules! implement_commands {
/// field names matching a pattern.
#[inline]
fn hscan_match<K: ToRedisArgs, P: ToRedisArgs, RV: FromRedisValue>
(&mut self, key: K, pattern: P) -> crate::types::RedisFuture<crate::cmd::AsyncIter<'_, RV>> {
(&mut self, key: K, pattern: P) -> crate::types::RedisFuture<'_, crate::cmd::AsyncIter<'_, RV>> {
let mut c = cmd("HSCAN");
c.arg(key).cursor_arg(0).arg("MATCH").arg(pattern);
Box::pin(async move {c.iter_async(self).await })
}

/// Incrementally iterate set elements.
#[inline]
fn sscan<K: ToRedisArgs, RV: FromRedisValue>(&mut self, key: K) -> crate::types::RedisFuture<crate::cmd::AsyncIter<'_, RV>> {
fn sscan<K: ToRedisArgs, RV: FromRedisValue>(&mut self, key: K) -> crate::types::RedisFuture<'_, crate::cmd::AsyncIter<'_, RV>> {
let mut c = cmd("SSCAN");
c.arg(key).cursor_arg(0);
Box::pin(async move {c.iter_async(self).await })
Expand All @@ -215,15 +215,15 @@ macro_rules! implement_commands {
/// Incrementally iterate set elements for elements matching a pattern.
#[inline]
fn sscan_match<K: ToRedisArgs, P: ToRedisArgs, RV: FromRedisValue>
(&mut self, key: K, pattern: P) -> crate::types::RedisFuture<crate::cmd::AsyncIter<'_, RV>> {
(&mut self, key: K, pattern: P) -> crate::types::RedisFuture<'_, crate::cmd::AsyncIter<'_, RV>> {
let mut c = cmd("SSCAN");
c.arg(key).cursor_arg(0).arg("MATCH").arg(pattern);
Box::pin(async move {c.iter_async(self).await })
}

/// Incrementally iterate sorted set elements.
#[inline]
fn zscan<K: ToRedisArgs, RV: FromRedisValue>(&mut self, key: K) -> crate::types::RedisFuture<crate::cmd::AsyncIter<'_, RV>> {
fn zscan<K: ToRedisArgs, RV: FromRedisValue>(&mut self, key: K) -> crate::types::RedisFuture<'_, crate::cmd::AsyncIter<'_, RV>> {
let mut c = cmd("ZSCAN");
c.arg(key).cursor_arg(0);
Box::pin(async move {c.iter_async(self).await })
Expand All @@ -232,7 +232,7 @@ macro_rules! implement_commands {
/// Incrementally iterate sorted set elements for elements matching a pattern.
#[inline]
fn zscan_match<K: ToRedisArgs, P: ToRedisArgs, RV: FromRedisValue>
(&mut self, key: K, pattern: P) -> crate::types::RedisFuture<crate::cmd::AsyncIter<'_, RV>> {
(&mut self, key: K, pattern: P) -> crate::types::RedisFuture<'_, crate::cmd::AsyncIter<'_, RV>> {
let mut c = cmd("ZSCAN");
c.arg(key).cursor_arg(0).arg("MATCH").arg(pattern);
Box::pin(async move {c.iter_async(self).await })
Expand Down
2 changes: 1 addition & 1 deletion redis/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl ConnectionAddr {
}

impl fmt::Display for ConnectionAddr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Cluster::get_connection_info depends on the return value from this function
match *self {
ConnectionAddr::Tcp(ref host, port) => write!(f, "{host}:{port}"),
Expand Down
7 changes: 6 additions & 1 deletion redis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,12 @@ assert_eq!(result, Ok(("foo".to_string(), b"bar".to_vec())));
//! [`futures`]:https://crates.io/crates/futures
//! [`tokio`]:https://tokio.rs

#![deny(non_camel_case_types)]
#![deny(
rust_2018_idioms,
nonstandard_style,
future_incompatible,
non_camel_case_types
)]
#![warn(missing_docs)]
#![cfg_attr(docsrs, warn(rustdoc::broken_intra_doc_links))]
#![cfg_attr(docsrs, feature(doc_cfg))]
Expand Down

0 comments on commit 840a37b

Please sign in to comment.