Skip to content

Commit 459c15d

Browse files
Merge pull request #77 from theseus-rs/enable-clippy-pedantic
build: Enable pedantic lints
2 parents 9105548 + 11335c2 commit 459c15d

File tree

9 files changed

+127
-74
lines changed

9 files changed

+127
-74
lines changed

postgresql_archive/src/archive.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ lazy_static! {
5454
struct GithubMiddleware;
5555

5656
impl GithubMiddleware {
57-
fn add_github_headers(&self, request: &mut Request) -> Result<()> {
57+
#[allow(clippy::unnecessary_wraps)]
58+
fn add_github_headers(request: &mut Request) -> Result<()> {
5859
let headers = request.headers_mut();
5960

6061
headers.append(
@@ -82,8 +83,8 @@ impl Middleware for GithubMiddleware {
8283
extensions: &mut Extensions,
8384
next: Next<'_>,
8485
) -> reqwest_middleware::Result<Response> {
85-
match self.add_github_headers(&mut request) {
86-
Ok(_) => next.run(request, extensions).await,
86+
match GithubMiddleware::add_github_headers(&mut request) {
87+
Ok(()) => next.run(request, extensions).await,
8788
Err(error) => Err(reqwest_middleware::Error::Middleware(error.into())),
8889
}
8990
}
@@ -131,12 +132,9 @@ async fn get_release(version: &Version) -> Result<Release> {
131132
}
132133

133134
for release in response_releases {
134-
let release_version = match Version::from_str(&release.tag_name) {
135-
Ok(release_version) => release_version,
136-
Err(_) => {
137-
warn!("Failed to parse release version {}", release.tag_name);
138-
continue;
139-
}
135+
let Ok(release_version) = Version::from_str(&release.tag_name) else {
136+
warn!("Failed to parse release version {}", release.tag_name);
137+
continue;
140138
};
141139

142140
if version.matches(&release_version) {
@@ -205,8 +203,7 @@ async fn get_asset<S: AsRef<str>>(version: &Version, target: S) -> Result<(Versi
205203

206204
match (asset, asset_hash) {
207205
(Some(asset), Some(asset_hash)) => Ok((asset_version, asset, asset_hash)),
208-
(None, _) => Err(AssetNotFound(asset_name.to_string())),
209-
(_, None) => Err(AssetNotFound(asset_name.to_string())),
206+
(_, None) | (None, _) => Err(AssetNotFound(asset_name.to_string())),
210207
}
211208
}
212209

@@ -226,6 +223,7 @@ pub async fn get_archive(version: &Version) -> Result<(Version, Bytes)> {
226223
/// is not found, then an [error](crate::error::Error) is returned.
227224
///
228225
/// Returns the archive version and bytes.
226+
#[allow(clippy::cast_precision_loss)]
229227
#[instrument(level = "debug", skip(target))]
230228
pub async fn get_archive_for_target<S: AsRef<str>>(
231229
version: &Version,
@@ -320,6 +318,7 @@ fn acquire_lock(out_dir: &Path) -> Result<PathBuf> {
320318
}
321319

322320
/// Extracts the compressed tar [bytes](Bytes) to the [out_dir](Path).
321+
#[allow(clippy::cast_precision_loss)]
323322
#[instrument(skip(bytes))]
324323
pub async fn extract(bytes: &Bytes, out_dir: &Path) -> Result<()> {
325324
let input = BufReader::new(Cursor::new(bytes));
@@ -328,13 +327,13 @@ pub async fn extract(bytes: &Bytes, out_dir: &Path) -> Result<()> {
328327
let mut files = 0;
329328
let mut extracted_bytes = 0;
330329

331-
let parent_dir = match out_dir.parent() {
332-
Some(parent) => parent,
333-
None => {
334-
debug!("No parent directory for {}", out_dir.to_string_lossy());
335-
out_dir
336-
}
330+
let parent_dir = if let Some(parent) = out_dir.parent() {
331+
parent
332+
} else {
333+
debug!("No parent directory for {}", out_dir.to_string_lossy());
334+
out_dir
337335
};
336+
338337
create_dir_all(parent_dir)?;
339338

340339
let lock_file = acquire_lock(parent_dir)?;
@@ -370,7 +369,7 @@ pub async fn extract(bytes: &Bytes, out_dir: &Path) -> Result<()> {
370369
}
371370
};
372371
let stripped_entry_header_path = entry_header_path.strip_prefix(prefix)?.to_path_buf();
373-
let mut entry_name = extract_dir.to_path_buf();
372+
let mut entry_name = extract_dir.clone();
374373
entry_name.push(stripped_entry_header_path);
375374

376375
if entry_type.is_dir() || entry_name.is_dir() {

postgresql_archive/src/blocking/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ lazy_static! {
1010
/// Gets the version of PostgreSQL for the specified [version](Version). If the version minor or release is not
1111
/// specified, then the latest version is returned. If a release for the [version](Version) is not found, then a
1212
/// [ReleaseNotFound](crate::Error::ReleaseNotFound) error is returned.
13+
///
14+
/// # Errors
15+
///
16+
/// Returns an error if the version is not found.
1317
pub fn get_version(version: &Version) -> crate::Result<Version> {
1418
RUNTIME
1519
.handle()
@@ -21,6 +25,10 @@ pub fn get_version(version: &Version) -> crate::Result<Version> {
2125
/// [error](crate::Error) is returned.
2226
///
2327
/// Returns the archive version and bytes.
28+
///
29+
/// # Errors
30+
///
31+
/// Returns an error if the version is not found.
2432
pub fn get_archive(version: &Version) -> crate::Result<(Version, Bytes)> {
2533
RUNTIME
2634
.handle()
@@ -33,6 +41,10 @@ pub fn get_archive(version: &Version) -> crate::Result<(Version, Bytes)> {
3341
/// is not found, then an [error](crate::error::Error) is returned.
3442
///
3543
/// Returns the archive version and bytes.
44+
///
45+
/// # Errors
46+
///
47+
/// Returns an error if the version or target is not found.
3648
pub fn get_archive_for_target<S: AsRef<str>>(
3749
version: &Version,
3850
target: S,
@@ -43,6 +55,10 @@ pub fn get_archive_for_target<S: AsRef<str>>(
4355
}
4456

4557
/// Extracts the compressed tar [bytes](Bytes) to the [out_dir](Path).
58+
///
59+
/// # Errors
60+
///
61+
/// Returns an error if the extraction fails.
4662
pub fn extract(bytes: &Bytes, out_dir: &Path) -> crate::Result<()> {
4763
RUNTIME
4864
.handle()

postgresql_archive/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@
104104
//! Uses PostgreSQL binaries from [theseus-rs/postgresql-binaries](https://github.com/theseus-rs/postgresql-binaries).
105105
106106
#![forbid(unsafe_code)]
107+
#![deny(clippy::pedantic)]
108+
#![allow(clippy::doc_markdown)]
109+
107110
#[macro_use]
108111
extern crate lazy_static;
109112

postgresql_archive/src/version.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub const V13: Version = Version::new(13, None, None);
4343
pub const V12: Version = Version::new(12, None, None);
4444

4545
impl Version {
46+
#[must_use]
4647
pub const fn new(major: u64, minor: Option<u64>, release: Option<u64>) -> Self {
4748
Self {
4849
major,
@@ -67,6 +68,7 @@ impl Version {
6768
/// 4. `15` does not match `16.1.0`
6869
/// 5. `16.0` does not match `16.1.0`
6970
/// 6. `16.1.0` does not match `16.1.1`
71+
#[must_use]
7072
pub fn matches(&self, version: &Version) -> bool {
7173
if self.major != version.major {
7274
return false;
@@ -87,12 +89,10 @@ impl fmt::Display for Version {
8789
let major = self.major.to_string();
8890
let minor = self
8991
.minor
90-
.map(|minor| format!(".{minor}"))
91-
.unwrap_or("".to_string());
92+
.map_or(String::new(), |minor| format!(".{minor}"));
9293
let release = self
9394
.release
94-
.map(|release| format!(".{release}"))
95-
.unwrap_or("".to_string());
95+
.map_or(String::new(), |release| format!(".{release}"));
9696
write!(formatter, "{major}{minor}{release}")
9797
}
9898
}

postgresql_embedded/src/blocking/mod.rs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,47 @@ lazy_static! {
77
static ref RUNTIME: Runtime = Runtime::new().unwrap();
88
}
99

10-
/// PostgreSQL server
10+
/// `PostgreSQL` server
1111
#[derive(Clone, Debug, Default)]
1212
pub struct PostgreSQL {
1313
inner: crate::postgresql::PostgreSQL,
1414
}
1515

16-
/// PostgreSQL server methods
16+
/// `PostgreSQL` server methods
1717
impl PostgreSQL {
1818
/// Create a new [`crate::postgresql::PostgreSQL`] instance
19+
#[must_use]
1920
pub fn new(version: Version, settings: Settings) -> Self {
2021
Self {
2122
inner: crate::postgresql::PostgreSQL::new(version, settings),
2223
}
2324
}
2425

25-
/// Get the [status](Status) of the PostgreSQL server
26+
/// Get the [status](Status) of the `PostgreSQL` server
27+
#[must_use]
2628
pub fn status(&self) -> Status {
2729
self.inner.status()
2830
}
2931

30-
/// Get the [version](Version) of the PostgreSQL server
32+
/// Get the [version](Version) of the `PostgreSQL` server
33+
#[must_use]
3134
pub fn version(&self) -> &Version {
3235
self.inner.version()
3336
}
3437

35-
/// Get the [settings](Settings) of the PostgreSQL server
38+
/// Get the [settings](Settings) of the `PostgreSQL` server
39+
#[must_use]
3640
pub fn settings(&self) -> &Settings {
3741
self.inner.settings()
3842
}
3943

4044
/// Set up the database by extracting the archive and initializing the database.
4145
/// If the installation directory already exists, the archive will not be extracted.
4246
/// If the data directory already exists, the database will not be initialized.
47+
///
48+
/// # Errors
49+
///
50+
/// Returns an error if the setup fails.
4351
pub fn setup(&mut self) -> Result<()> {
4452
RUNTIME
4553
.handle()
@@ -48,20 +56,32 @@ impl PostgreSQL {
4856

4957
/// Start the database and wait for the startup to complete.
5058
/// If the port is set to `0`, the database will be started on a random port.
59+
///
60+
/// # Errors
61+
///
62+
/// Returns an error if the startup fails.
5163
pub fn start(&mut self) -> Result<()> {
5264
RUNTIME
5365
.handle()
5466
.block_on(async move { self.inner.start().await })
5567
}
5668

5769
/// Stop the database gracefully (smart mode) and wait for the shutdown to complete.
70+
///
71+
/// # Errors
72+
///
73+
/// Returns an error if the shutdown fails.
5874
pub fn stop(&self) -> Result<()> {
5975
RUNTIME
6076
.handle()
6177
.block_on(async move { self.inner.stop().await })
6278
}
6379

6480
/// Create a new database with the given name.
81+
///
82+
/// # Errors
83+
///
84+
/// Returns an error if the database creation fails.
6585
pub fn create_database<S>(&self, database_name: S) -> Result<()>
6686
where
6787
S: AsRef<str> + std::fmt::Debug,
@@ -72,6 +92,10 @@ impl PostgreSQL {
7292
}
7393

7494
/// Check if a database with the given name exists.
95+
///
96+
/// # Errors
97+
///
98+
/// Returns an error if the database existence check fails.
7599
pub fn database_exists<S>(&self, database_name: S) -> Result<bool>
76100
where
77101
S: AsRef<str> + std::fmt::Debug,
@@ -82,6 +106,10 @@ impl PostgreSQL {
82106
}
83107

84108
/// Drop a database with the given name.
109+
///
110+
/// # Errors
111+
///
112+
/// Returns an error if the database drop fails.
85113
pub fn drop_database<S>(&self, database_name: S) -> Result<()>
86114
where
87115
S: AsRef<str> + std::fmt::Debug,

postgresql_embedded/src/error.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use std::string::FromUtf8Error;
22

3-
/// PostgreSQL embedded result type
3+
/// `PostgreSQL` embedded result type
44
pub type Result<T, E = Error> = core::result::Result<T, E>;
55

6-
/// Errors that can occur when using PostgreSQL embedded
6+
/// Errors that can occur when using `PostgreSQL` embedded
77
#[derive(Debug, thiserror::Error)]
88
pub enum Error {
9-
/// Error when PostgreSQL archive operations fail
9+
/// Error when `PostgreSQL` archive operations fail
1010
#[error(transparent)]
1111
ArchiveError(postgresql_archive::Error),
1212
/// Error when a command fails
@@ -38,7 +38,7 @@ pub enum Error {
3838
IoError(anyhow::Error),
3939
}
4040

41-
/// Convert PostgreSQL [archive errors](postgresql_archive::Error) to an [embedded errors](Error::ArchiveError)
41+
/// Convert `PostgreSQL` [archive errors](postgresql_archive::Error) to an [embedded errors](Error::ArchiveError)
4242
impl From<postgresql_archive::Error> for Error {
4343
fn from(error: postgresql_archive::Error) -> Self {
4444
Error::ArchiveError(error)

postgresql_embedded/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@
107107
//! Uses PostgreSQL binaries from [theseus-rs/postgresql-binaries](https://github.com/theseus-rs/postgresql-binaries).
108108
109109
#![forbid(unsafe_code)]
110+
#![deny(clippy::pedantic)]
110111
#![allow(dead_code)]
112+
#![allow(clippy::doc_markdown)]
111113

112114
#[cfg(feature = "blocking")]
113115
pub mod blocking;

0 commit comments

Comments
 (0)