Skip to content

Commit e0e6ea0

Browse files
committed
Clippy updates. Update regex version
1 parent 697dfef commit e0e6ea0

File tree

16 files changed

+144
-126
lines changed

16 files changed

+144
-126
lines changed

benches/client.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,12 @@ async fn main() {
5959
1000000.0 * successful_count as f64 / (end - start).as_micros() as f64
6060
);
6161
println!(
62-
"{} successful requests, {} errors",
63-
successful_count, error_count
62+
"{successful_count} successful requests, {error_count} errors"
6463
);
6564
}
6665

6766
async fn prepare_influxdb(client: &Client, db_name: &str) {
68-
let create_db_stmt = format!("CREATE DATABASE {}", db_name);
67+
let create_db_stmt = format!("CREATE DATABASE {db_name}");
6968
client
7069
.query(&ReadQuery::new(create_db_stmt))
7170
.await

influxdb/Cargo.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ futures-util = "0.3.17"
1818
http = "0.2.4"
1919
influxdb_derive = { version = "0.5.0", optional = true }
2020
lazy_static = "1.4.0"
21-
regex = "1.7.0"
21+
regex = "1.11.0"
2222
reqwest = { version = "0.11.13", default-features = false, optional = true }
2323
surf = { version = "2.3.2", default-features = false, optional = true }
2424
serde = { version = "1.0.104", features = ["derive"], optional = true }
@@ -41,3 +41,11 @@ wasm-client = ["surf", "surf/wasm-client"]
4141
[dev-dependencies]
4242
indoc = "1.0"
4343
tokio = { version = "1.23", features = ["macros", "rt-multi-thread"] }
44+
45+
[lints.clippy]
46+
pedantic = { level = "warn", priority = -1 }
47+
nursery = { level = "warn", priority = -1 }
48+
module_name_repetitions = "allow"
49+
missing_panics_doc = "allow"
50+
missing_errors_doc = "allow"
51+
future_not_send = "allow"

influxdb/src/client/mod.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
//! Client which can read and write data from InfluxDB.
1+
//! Client which can read and write data from `InfluxDB`.
22
//!
33
//! # Arguments
44
//!
5-
//! * `url`: The URL where InfluxDB is running (ex. `http://localhost:8086`).
5+
//! * `url`: The URL where `InfluxDB` is running (ex. `http://localhost:8086`).
66
//! * `database`: The Database against which queries and writes will be run.
77
//!
88
//! # Examples
@@ -49,7 +49,7 @@ impl<'a> Debug for RedactPassword<'a> {
4949
_ => (*k, v.as_str()),
5050
})
5151
.collect::<BTreeMap<&'static str, &str>>();
52-
f.debug_map().entries(entries.into_iter()).finish()
52+
f.debug_map().entries(entries).finish()
5353
}
5454
}
5555

@@ -67,7 +67,7 @@ impl Client {
6767
///
6868
/// # Arguments
6969
///
70-
/// * `url`: The URL where InfluxDB is running (ex. `http://localhost:8086`).
70+
/// * `url`: The URL where `InfluxDB` is running (ex. `http://localhost:8086`).
7171
/// * `database`: The Database against which queries and writes will be run.
7272
///
7373
/// # Examples
@@ -85,7 +85,7 @@ impl Client {
8585
{
8686
let mut parameters = HashMap::<&str, String>::new();
8787
parameters.insert("db", database.into());
88-
Client {
88+
Self {
8989
url: Arc::new(url.into()),
9090
parameters: Arc::new(parameters),
9191
client: HttpClient::new(),
@@ -96,7 +96,7 @@ impl Client {
9696
///
9797
/// # Arguments
9898
///
99-
/// * username: The Username for InfluxDB.
99+
/// * username: The Username for `InfluxDB`.
100100
/// * password: The Password for the user.
101101
///
102102
/// # Examples
@@ -127,33 +127,35 @@ impl Client {
127127
}
128128

129129
/// Returns the name of the database the client is using
130+
#[must_use]
130131
pub fn database_name(&self) -> &str {
131132
// safe to unwrap: we always set the database name in `Self::new`
132133
self.parameters.get("db").unwrap()
133134
}
134135

135-
/// Returns the URL of the InfluxDB installation the client is using
136+
/// Returns the URL of the `InfluxDB` installation the client is using
137+
#[must_use]
136138
pub fn database_url(&self) -> &str {
137139
&self.url
138140
}
139141

140-
/// Pings the InfluxDB Server
142+
/// Pings the `InfluxDB` Server
141143
///
142144
/// Returns a tuple of build type and version number
143145
pub async fn ping(&self) -> Result<(String, String), Error> {
146+
const BUILD_HEADER: &str = "X-Influxdb-Build";
147+
const VERSION_HEADER: &str = "X-Influxdb-Version";
148+
144149
let url = &format!("{}/ping", self.url);
145150
let res = self
146151
.client
147152
.get(url)
148153
.send()
149154
.await
150155
.map_err(|err| Error::ProtocolError {
151-
error: format!("{}", err),
156+
error: format!("{err}"),
152157
})?;
153158

154-
const BUILD_HEADER: &str = "X-Influxdb-Build";
155-
const VERSION_HEADER: &str = "X-Influxdb-Version";
156-
157159
#[cfg(feature = "reqwest")]
158160
let (build, version) = {
159161
let hdrs = res.headers();
@@ -172,9 +174,9 @@ impl Client {
172174
Ok((build.unwrap().to_owned(), version.unwrap().to_owned()))
173175
}
174176

175-
/// Sends a [`ReadQuery`](crate::ReadQuery) or [`WriteQuery`](crate::WriteQuery) to the InfluxDB Server.
177+
/// Sends a [`ReadQuery`](crate::ReadQuery) or [`WriteQuery`](crate::WriteQuery) to the `InfluxDB` Server.
176178
///
177-
/// A version capable of parsing the returned string is available under the [serde_integration](crate::integrations::serde_integration)
179+
/// A version capable of parsing the returned string is available under the [`serde_integration`](crate::integrations::serde_integration)
178180
///
179181
/// # Arguments
180182
///
@@ -267,15 +269,15 @@ impl Client {
267269
// todo: improve error parsing without serde
268270
if s.contains("\"error\"") {
269271
return Err(Error::DatabaseError {
270-
error: format!("influxdb error: \"{}\"", s),
272+
error: format!("influxdb error: \"{s}\""),
271273
});
272274
}
273275

274276
Ok(s)
275277
}
276278
}
277279

278-
pub(crate) fn check_status(res: &HttpResponse) -> Result<(), Error> {
280+
pub fn check_status(res: &HttpResponse) -> Result<(), Error> {
279281
let status = res.status();
280282
if status == StatusCode::UNAUTHORIZED.as_u16() {
281283
Err(Error::AuthorizationError)
@@ -294,7 +296,7 @@ mod tests {
294296
#[test]
295297
fn test_client_debug_redacted_password() {
296298
let client = Client::new("https://localhost:8086", "db").with_auth("user", "pass");
297-
let actual = format!("{:#?}", client);
299+
let actual = format!("{client:#?}");
298300
let expected = indoc! { r#"
299301
Client {
300302
url: "https://localhost:8086",

influxdb/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub enum Error {
2121
DeserializationError { error: String },
2222

2323
#[error("InfluxDB encountered the following error: {error}")]
24-
/// Error which has happened inside InfluxDB
24+
/// Error which has happened inside `InfluxDB`
2525
DatabaseError { error: String },
2626

2727
#[error("authentication error. No or incorrect credentials")]

influxdb/src/integrations/serde_integration/de.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,10 @@ where
349349
&mut self,
350350
seed: K,
351351
) -> Result<K::Value, Self::Error> {
352-
match self.data.next_element_seed(seed)? {
353-
Some(value) => Ok(value),
354-
None => Err(Error::custom("next_value_seed called but no value")),
355-
}
352+
(self.data.next_element_seed(seed)?).map_or_else(
353+
|| Err(Error::custom("next_value_seed called but no value")),
354+
Ok,
355+
)
356356
}
357357
}
358358

@@ -382,7 +382,7 @@ mod tests {
382382

383383
impl<T> From<Series<T>> for EqSeries<T> {
384384
fn from(Series { name, values }: Series<T>) -> Self {
385-
EqSeries { name, values }
385+
Self { name, values }
386386
}
387387
}
388388

influxdb/src/integrations/serde_integration/mod.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
//! Serde Integration for InfluxDB. Provides deserialization of query returns.
1+
//! Serde Integration for `InfluxDB`. Provides deserialization of query returns.
22
//!
33
//! When querying multiple series in the same query (e.g. with a regex query), it might be desirable to flat map
44
//! the resulting series into a single `Vec` like so. The example assumes, that there are weather readings in multiple
55
//! series named `weather_<city_name>` (e.g. `weather_berlin`, or `weather_london`). Since we're using a Regex query,
66
//! we don't actually know which series will be returned. To assign the city name to the series, we can use the series
7-
//! `name`, InfluxDB provides alongside query results.
7+
//! `name`, `InfluxDB` provides alongside query results.
88
//!
99
//! ```rust,no_run
1010
//! use influxdb::{Client, Query};
@@ -64,27 +64,25 @@ pub struct DatabaseQueryResult {
6464
}
6565

6666
impl DatabaseQueryResult {
67-
pub fn deserialize_next<T: 'static>(&mut self) -> Result<Return<T>, Error>
67+
pub fn deserialize_next<T>(&mut self) -> Result<Return<T>, Error>
6868
where
69-
T: DeserializeOwned + Send,
69+
T: 'static + DeserializeOwned + Send,
7070
{
7171
serde_json::from_value::<Return<T>>(self.results.remove(0)).map_err(|err| {
7272
Error::DeserializationError {
73-
error: format!("could not deserialize: {}", err),
73+
error: format!("could not deserialize: {err}"),
7474
}
7575
})
7676
}
7777

78-
pub fn deserialize_next_tagged<TAG, T: 'static>(
79-
&mut self,
80-
) -> Result<TaggedReturn<TAG, T>, Error>
78+
pub fn deserialize_next_tagged<TAG, T>(&mut self) -> Result<TaggedReturn<TAG, T>, Error>
8179
where
8280
TAG: DeserializeOwned + Send,
83-
T: DeserializeOwned + Send,
81+
T: 'static + DeserializeOwned + Send,
8482
{
8583
serde_json::from_value::<TaggedReturn<TAG, T>>(self.results.remove(0)).map_err(|err| {
8684
Error::DeserializationError {
87-
error: format!("could not deserialize: {}", err),
85+
error: format!("could not deserialize: {err}"),
8886
}
8987
})
9088
}
@@ -98,7 +96,7 @@ pub struct Return<T> {
9896
}
9997

10098
#[derive(Debug)]
101-
/// Represents a returned series from InfluxDB
99+
/// Represents a returned series from `InfluxDB`
102100
pub struct Series<T> {
103101
pub name: String,
104102
pub values: Vec<T>,
@@ -112,7 +110,7 @@ pub struct TaggedReturn<TAG, T> {
112110
}
113111

114112
#[derive(Debug)]
115-
/// Represents a returned series from InfluxDB
113+
/// Represents a returned series from `InfluxDB`
116114
pub struct TaggedSeries<TAG, T> {
117115
pub name: String,
118116
pub tags: TAG,
@@ -122,7 +120,7 @@ pub struct TaggedSeries<TAG, T> {
122120
impl Client {
123121
pub async fn json_query(&self, q: ReadQuery) -> Result<DatabaseQueryResult, Error> {
124122
let query = q.build().map_err(|err| Error::InvalidQueryError {
125-
error: format!("{}", err),
123+
error: format!("{err}"),
126124
})?;
127125

128126
let read_query = query.get();
@@ -174,7 +172,7 @@ impl Client {
174172
// Json has another structure, let's try actually parsing it to the type we're deserializing
175173
serde_json::from_slice::<DatabaseQueryResult>(&body).map_err(|err| {
176174
Error::DeserializationError {
177-
error: format!("serde error: {}", err),
175+
error: format!("serde error: {err}"),
178176
}
179177
})
180178
}

influxdb/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//!
66
//! ## Currently Supported Features
77
//!
8-
//! - Reading and Writing to InfluxDB
8+
//! - Reading and Writing to `InfluxDB`
99
//! - Optional Serde Support for Deserialization
1010
//! - Running multiple queries in one request (e.g. `SELECT * FROM weather_berlin; SELECT * FROM weather_london`)
1111
//! - Writing single or multiple measurements in one request (e.g. `WriteQuery` or `Vec<WriteQuery>` argument)
@@ -24,7 +24,7 @@
2424
//! influxdb = { version = "0.5.2", features = ["derive"] }
2525
//! ```
2626
//!
27-
//! For an example with using Serde deserialization, please refer to [serde_integration](crate::integrations::serde_integration)
27+
//! For an example with using Serde deserialization, please refer to [`serde_integration`](crate::integrations::serde_integration)
2828
//!
2929
//! ```rust,no_run
3030
//! use influxdb::{Client, Query, Timestamp, ReadQuery};
@@ -77,7 +77,7 @@
7777
//!
7878
//! # Choice of HTTP backend
7979
//!
80-
//! To communicate with InfluxDB, you can choose the HTTP backend to be used configuring the appropriate feature. We recommend sticking with the default reqwest-based client, unless you really need async-std compatibility.
80+
//! To communicate with `InfluxDB`, you can choose the HTTP backend to be used configuring the appropriate feature. We recommend sticking with the default reqwest-based client, unless you really need async-std compatibility.
8181
//!
8282
//! - **[hyper](https://github.com/hyperium/hyper)** (through reqwest, used by default), with [rustls](https://github.com/ctz/rustls)
8383
//! ```toml

0 commit comments

Comments
 (0)