Skip to content

Commit

Permalink
auto formated code, stable cargo 1.82.0 (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemIsmagilov authored Nov 9, 2024
1 parent 1cc798f commit c5a522e
Show file tree
Hide file tree
Showing 57 changed files with 422 additions and 247 deletions.
12 changes: 8 additions & 4 deletions benches/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ fn bench_redis_async_long_pipeline(b: &mut Bencher) {

let client = get_redis_client();
let runtime = current_thread_runtime();
let mut con = runtime.block_on(client.get_multiplexed_async_connection()).unwrap();
let mut con = runtime
.block_on(client.get_multiplexed_async_connection())
.unwrap();

b.iter(|| {
runtime
Expand All @@ -136,7 +138,7 @@ fn bench_redis_multiplexed_async_long_pipeline(b: &mut Bencher) {
let mut con = runtime
.block_on(client.get_multiplexed_tokio_connection())
.unwrap();

b.iter(|| {
runtime
.block_on(async {
Expand Down Expand Up @@ -165,7 +167,9 @@ fn bench_fred_long_pipeline(b: &mut Bencher) {
.block_on(async {
let pipeline = client.pipeline();
for i in 0..PIPELINE_QUERIES {
pipeline.set(format!("foo{}", i), "bar", None, None, false).await?;
pipeline
.set(format!("foo{}", i), "bar", None, None, false)
.await?;
}

let _result: Vec<String> = pipeline.all().await?;
Expand Down Expand Up @@ -213,7 +217,7 @@ fn bench_simple(c: &mut Criterion) {
.bench_function(
"rustis_simple_getsetdel_pipeline",
bench_rustis_simple_getsetdel_pipeline,
);
);
group.finish();
}

Expand Down
9 changes: 4 additions & 5 deletions examples/actix_crud.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use actix_web::{delete, get, http::StatusCode, post, web, App, HttpServer, HttpResponse, Responder};
use actix_web::{
delete, get, http::StatusCode, post, web, App, HttpResponse, HttpServer, Responder,
};
use rustis::{
client::Client,
commands::{GenericCommands, StringCommands},
Expand Down Expand Up @@ -28,10 +30,7 @@ async fn main() -> std::io::Result<()> {
}

#[get("/{key}")]
async fn read(
redis: web::Data<Client>,
key: web::Path<String>,
) -> Result<String, ServiceError> {
async fn read(redis: web::Data<Client>, key: web::Path<String>) -> Result<String, ServiceError> {
let key = key.into_inner();
let value: Option<String> = redis.get(&key).await?;
value.ok_or_else(|| {
Expand Down
2 changes: 1 addition & 1 deletion examples/actix_long_polling_pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async fn publish(
return Err(ServiceError::new(
StatusCode::BAD_REQUEST,
"Message not provided",
))
));
};

let channel = channel.into_inner();
Expand Down
10 changes: 7 additions & 3 deletions examples/simple.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use rustis::{client::Client, Result, commands::{StringCommands, GenericCommands}};
use rustis::{
client::Client,
commands::{GenericCommands, StringCommands},
Result,
};

#[tokio::main]
async fn main() -> Result<()> {
Expand All @@ -9,7 +13,7 @@ async fn main() -> Result<()> {
client.set(key, 42.423456).await?;
let _: f64 = client.get(key).await?;
client.del(key).await?;
}
}

Ok(())
}
}
4 changes: 3 additions & 1 deletion src/client/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ impl ClientState {
match self.cache.get(key) {
Some(cache_entry) => match cache_entry.downcast_ref::<S>() {
Some(cache_entry) => Ok(Some(cache_entry)),
None => Err(Error::Client(format!("Cannot downcast cache entry '{key}'"))),
None => Err(Error::Client(format!(
"Cannot downcast cache entry '{key}'"
))),
},
None => Ok(None),
}
Expand Down
11 changes: 9 additions & 2 deletions src/client/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
use crate::{Error, Result};
#[cfg(feature = "tls")]
use native_tls::{Certificate, Identity, Protocol, TlsConnector, TlsConnectorBuilder};
use std::{collections::HashMap, fmt::{self, Display, Write}, str::FromStr, time::Duration};
use std::{
collections::HashMap,
fmt::{self, Display, Write},
str::FromStr,
time::Duration,
};
use url::Url;

const DEFAULT_PORT: u16 = 6379;
Expand Down Expand Up @@ -600,7 +605,9 @@ impl Display for Config {
} else {
f.write_char('&')?;
}
f.write_fmt(format_args!("wait_between_failures={wait_between_failures}"))?;
f.write_fmt(format_args!(
"wait_between_failures={wait_between_failures}"
))?;
}
if let Some(username) = username {
if !query_separator {
Expand Down
8 changes: 5 additions & 3 deletions src/client/prepared_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use crate::{
};
use std::marker::PhantomData;

type CustomConverter<'a, R> =
dyn Fn(RespBuf, Command, &'a Client) -> Future<'a, R> + Send + Sync;
type CustomConverter<'a, R> = dyn Fn(RespBuf, Command, &'a Client) -> Future<'a, R> + Send + Sync;

/// Wrapper around a command about to be send with a marker for the response type
/// and a few options to decide how the response send back by Redis should be processed.
Expand Down Expand Up @@ -64,6 +63,9 @@ where
}

/// Shortcut function to creating a [`PreparedCommand`](PreparedCommand).
pub(crate) fn prepare_command<'a, E, R: Response>(executor: E, command: Command) -> PreparedCommand<'a, E, R> {
pub(crate) fn prepare_command<'a, E, R: Response>(
executor: E,
command: Command,
) -> PreparedCommand<'a, E, R> {
PreparedCommand::new(executor, command)
}
29 changes: 19 additions & 10 deletions src/client/pub_sub_stream.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use crate::{
client::{Client, ClientPreparedCommand}, commands::InternalPubSubCommands, network::PubSubSender, resp::{ByteBufSeed, CommandArgs, SingleArg, SingleArgCollection}, Error, PubSubReceiver, Result
client::{Client, ClientPreparedCommand},
commands::InternalPubSubCommands,
network::PubSubSender,
resp::{ByteBufSeed, CommandArgs, SingleArg, SingleArgCollection},
Error, PubSubReceiver, Result,
};
use futures_util::{Stream, StreamExt};
use serde::{
Expand Down Expand Up @@ -102,7 +106,10 @@ impl PubSubSplitSink {

for channel in &channels {
if self.channels.iter().any(|c| c == channel) {
return Err(Error::Client(format!("pub sub stream already subscribed to channel `{}`", String::from_utf8_lossy(channel))));
return Err(Error::Client(format!(
"pub sub stream already subscribed to channel `{}`",
String::from_utf8_lossy(channel)
)));
}
}

Expand All @@ -125,7 +132,10 @@ impl PubSubSplitSink {

for pattern in &patterns {
if self.patterns.iter().any(|p| p == pattern) {
return Err(Error::Client(format!("pub sub stream already subscribed to pattern `{}`", String::from_utf8_lossy(pattern))));
return Err(Error::Client(format!(
"pub sub stream already subscribed to pattern `{}`",
String::from_utf8_lossy(pattern)
)));
}
}

Expand All @@ -148,7 +158,10 @@ impl PubSubSplitSink {

for shardchannel in &shardchannels {
if self.shardchannels.iter().any(|c| c == shardchannel) {
return Err(Error::Client(format!("pub sub stream already subscribed to shard channel `{}`", String::from_utf8_lossy(shardchannel))));
return Err(Error::Client(format!(
"pub sub stream already subscribed to shard channel `{}`",
String::from_utf8_lossy(shardchannel)
)));
}
}

Expand Down Expand Up @@ -321,11 +334,7 @@ pub struct PubSubStream {
}

impl PubSubStream {
pub(crate) fn new(
sender: PubSubSender,
receiver: PubSubReceiver,
client: Client,
) -> Self {
pub(crate) fn new(sender: PubSubSender, receiver: PubSubReceiver, client: Client) -> Self {
Self {
split_sink: PubSubSplitSink {
closed: false,
Expand Down Expand Up @@ -451,7 +460,7 @@ impl PubSubStream {
}

/// Splits this object into separate [`Sink`](PubSubSplitSink) and [`Stream`](PubSubSplitStream) objects.
/// This can be useful when you want to split ownership between tasks.
/// This can be useful when you want to split ownership between tasks.
pub fn split(self) -> (PubSubSplitSink, PubSubSplitStream) {
(self.split_sink, self.split_stream)
}
Expand Down
21 changes: 14 additions & 7 deletions src/commands/bitmap_commands.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::{
client::{prepare_command, PreparedCommand},
resp::{
cmd, CommandArgs, MultipleArgsCollection, SingleArg, SingleArgCollection, ToArgs,
},
resp::{cmd, CommandArgs, MultipleArgsCollection, SingleArg, SingleArgCollection, ToArgs},
};

/// A group of Redis commands related to [`Bitmaps`](https://redis.io/docs/data-types/bitmaps/)
Expand Down Expand Up @@ -244,9 +242,16 @@ where
fn write_args(&self, args: &mut CommandArgs) {
match self {
BitFieldSubCommand::Get(g) => args.arg_ref(g),
BitFieldSubCommand::Set(encoding, offset, value) =>
args.arg("SET").arg_ref(encoding).arg_ref(offset).arg(*value),
BitFieldSubCommand::IncrBy(encoding, offset, increment) => args.arg("INCRBY").arg_ref(encoding).arg_ref(offset).arg(*increment),
BitFieldSubCommand::Set(encoding, offset, value) => args
.arg("SET")
.arg_ref(encoding)
.arg_ref(offset)
.arg(*value),
BitFieldSubCommand::IncrBy(encoding, offset, increment) => args
.arg("INCRBY")
.arg_ref(encoding)
.arg_ref(offset)
.arg(*increment),
BitFieldSubCommand::Overflow(overflow) => args.arg("OVERFLOW").arg_ref(overflow),
};
}
Expand Down Expand Up @@ -279,7 +284,9 @@ where
O: SingleArg,
{
fn write_args(&self, args: &mut CommandArgs) {
args.arg("GET").arg_ref(&self.encoding).arg_ref(&self.offset);
args.arg("GET")
.arg_ref(&self.encoding)
.arg_ref(&self.offset);
}
}

Expand Down
12 changes: 10 additions & 2 deletions src/commands/blocking_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ pub trait BlockingCommands<'a> {
/// # See Also
/// [<https://redis.io/commands/blpop/>](https://redis.io/commands/blpop/)
#[must_use]
fn blpop<K, KK, K1, V>(self, keys: KK, timeout: f64) -> PreparedCommand<'a, Self, Option<(K1, V)>>
fn blpop<K, KK, K1, V>(
self,
keys: KK,
timeout: f64,
) -> PreparedCommand<'a, Self, Option<(K1, V)>>
where
Self: Sized,
K: SingleArg,
Expand All @@ -177,7 +181,11 @@ pub trait BlockingCommands<'a> {
/// # See Also
/// [<https://redis.io/commands/brpop/>](https://redis.io/commands/brpop/)
#[must_use]
fn brpop<K, KK, K1, V>(self, keys: KK, timeout: f64) -> PreparedCommand<'a, Self, Option<(K1, V)>>
fn brpop<K, KK, K1, V>(
self,
keys: KK,
timeout: f64,
) -> PreparedCommand<'a, Self, Option<(K1, V)>>
where
Self: Sized,
K: SingleArg,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/cluster_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ impl<'de> Deserialize<'de> for LegacyClusterNodeResult {
preferred_endpoint,
ip,
hostname,
port
port,
})
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/commands/cuckoo_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,11 @@ impl CfReserveOptions {
/// The default value is 20.
pub fn maxiterations(mut self, maxiterations: usize) -> Self {
Self {
command_args: self.command_args.arg("MAXITERATIONS").arg(maxiterations).build(),
command_args: self
.command_args
.arg("MAXITERATIONS")
.arg(maxiterations)
.build(),
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/commands/geo_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,11 +414,17 @@ where
E: de::Error,
{
let Ok(distance) = std::str::from_utf8(v) else {
return Err(de::Error::invalid_value(Unexpected::Bytes(v), &"A valid f64 encoded in an UTF8 string"));
return Err(de::Error::invalid_value(
Unexpected::Bytes(v),
&"A valid f64 encoded in an UTF8 string",
));
};

let Ok(distance) = distance.parse::<f64>() else {
return Err(de::Error::invalid_value(Unexpected::Bytes(v), &"A valid f64 encoded in an UTF8 string"));
return Err(de::Error::invalid_value(
Unexpected::Bytes(v),
&"A valid f64 encoded in an UTF8 string",
));
};

Ok(GeoSearchResultField::Distance(distance))
Expand Down
Loading

0 comments on commit c5a522e

Please sign in to comment.