Skip to content

Commit ba29978

Browse files
committed
Strict clippy mode fixes
1 parent c44ebb8 commit ba29978

File tree

11 files changed

+138
-67
lines changed

11 files changed

+138
-67
lines changed

src/common.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use crate::exceptions::rust_errors::RustPSQLDriverPyResult;
77
/// Add new module to the parent one.
88
///
99
/// You can find out more information from this issue
10-
/// https://github.com/PyO3/pyo3/issues/759
10+
/// <https://github.com/PyO3/pyo3/issues/759>
1111
///
12-
/// # Error
12+
/// # Errors
1313
///
1414
/// May return Err Result if can't build module or change modules.
1515
pub fn add_module(
@@ -28,6 +28,13 @@ pub fn add_module(
2828
Ok(())
2929
}
3030

31+
/// Simple wrapper for pyo3 `pyo3_asyncio::tokio::future_into_py`.
32+
///
33+
/// It wraps incoming Future and return internal Result.
34+
///
35+
/// # Errors
36+
///
37+
/// May return Err Result if future acts incorrect.
3138
pub fn rustengine_future<F, T>(py: Python<'_>, future: F) -> RustPSQLDriverPyResult<&PyAny>
3239
where
3340
F: Future<Output = RustPSQLDriverPyResult<T>> + Send + 'static,

src/driver/connection.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ pub struct Connection {
2222

2323
#[pymethods]
2424
impl Connection {
25+
/// Execute statement with or witout parameters.
26+
///
27+
/// # Errors
28+
///
29+
/// May return Err Result if
30+
/// 1) Cannot convert incoming parameters
31+
/// 2) Cannot prepare statement
32+
/// 3) Cannot execute query
2533
pub fn execute<'a>(
2634
&'a self,
2735
py: Python<'a>,
@@ -32,12 +40,12 @@ impl Connection {
3240

3341
let mut params: Vec<PythonDTO> = vec![];
3442
if let Some(parameters) = parameters {
35-
params = convert_parameters(parameters)?
43+
params = convert_parameters(parameters)?;
3644
}
3745

3846
rustengine_future(py, async move {
3947
let mut vec_parameters: Vec<&(dyn ToSql + Sync)> = Vec::with_capacity(params.len());
40-
for param in params.iter() {
48+
for param in &params {
4149
vec_parameters.push(param);
4250
}
4351
let db_client_guard = db_client_arc.read().await;
@@ -52,6 +60,8 @@ impl Connection {
5260
})
5361
}
5462

63+
/// Return new instance of transaction.
64+
#[must_use]
5565
pub fn transaction(
5666
&self,
5767
isolation_level: Option<IsolationLevel>,

src/driver/connection_pool.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212

1313
use super::connection::Connection;
1414

15-
/// PSQLPool for internal use only.
15+
/// `PSQLPool` for internal use only.
1616
///
1717
/// It is not exposed to python.
1818
pub struct RustPSQLPool {
@@ -27,6 +27,7 @@ pub struct RustPSQLPool {
2727

2828
impl RustPSQLPool {
2929
/// Create new `RustPSQLPool`.
30+
#[must_use]
3031
pub fn new(
3132
username: Option<String>,
3233
password: Option<String>,
@@ -50,7 +51,7 @@ impl RustPSQLPool {
5051
impl RustPSQLPool {
5152
/// Return new single connection.
5253
///
53-
/// # Errors:
54+
/// # Errors
5455
/// May return Err Result if cannot get new connection from the pool.
5556
pub async fn inner_connection(&self) -> RustPSQLDriverPyResult<Connection> {
5657
let db_pool_arc = self.db_pool.clone();
@@ -73,7 +74,7 @@ impl RustPSQLPool {
7374
///
7475
/// Prepare statement and cache it, then execute.
7576
///
76-
/// # Errors:
77+
/// # Errors
7778
/// May return Err Result if cannot retrieve new connection
7879
/// or prepare statement or execute statement.
7980
pub async fn inner_execute(
@@ -94,7 +95,7 @@ impl RustPSQLPool {
9495
.await?;
9596

9697
let mut vec_parameters: Vec<&(dyn ToSql + Sync)> = Vec::with_capacity(parameters.len());
97-
for param in parameters.iter() {
98+
for param in &parameters {
9899
vec_parameters.push(param);
99100
}
100101

@@ -109,9 +110,9 @@ impl RustPSQLPool {
109110

110111
/// Create new Database pool.
111112
///
112-
/// # Errors:
113+
/// # Errors
113114
/// May return Err Result if Database pool is already initialized,
114-
/// max_db_pool_size is less than 2 or it's impossible to build db pool.
115+
/// `max_db_pool_size` is less than 2 or it's impossible to build db pool.
115116
pub async fn inner_startup(&self) -> RustPSQLDriverPyResult<()> {
116117
let db_pool_arc = self.db_pool.clone();
117118
let password = self.password.clone();
@@ -177,6 +178,7 @@ pub struct PSQLPool {
177178
#[pymethods]
178179
impl PSQLPool {
179180
#[new]
181+
#[must_use]
180182
pub fn new(
181183
username: Option<String>,
182184
password: Option<String>,
@@ -200,7 +202,7 @@ impl PSQLPool {
200202

201203
/// Startup Database Pool.
202204
///
203-
/// # Errors:
205+
/// # Errors
204206
/// May return Err Result if `inner_startup` returns error.
205207
pub fn startup<'a>(&'a self, py: Python<'a>) -> RustPSQLDriverPyResult<&'a PyAny> {
206208
let psql_pool_arc = self.rust_psql_pool.clone();
@@ -213,7 +215,7 @@ impl PSQLPool {
213215

214216
/// Return single connection.
215217
///
216-
/// # Errors:
218+
/// # Errors
217219
/// May return Err Result if `inner_connection` returns error.
218220
pub fn connection<'a>(&'a self, py: Python<'a>) -> RustPSQLDriverPyResult<&'a PyAny> {
219221
let psql_pool_arc = self.rust_psql_pool.clone();
@@ -226,7 +228,7 @@ impl PSQLPool {
226228

227229
/// Execute querystring with parameters.
228230
///
229-
/// # Errors:
231+
/// # Errors
230232
/// May return Err Result if cannot convert parameters
231233
/// or `inner_execute` returns Err.
232234
pub fn execute<'a>(
@@ -238,7 +240,7 @@ impl PSQLPool {
238240
let engine_arc = self.rust_psql_pool.clone();
239241
let mut params: Vec<PythonDTO> = vec![];
240242
if let Some(parameters) = parameters {
241-
params = convert_parameters(parameters)?
243+
params = convert_parameters(parameters)?;
242244
}
243245

244246
rustengine_future(py, async move {

src/driver/cursor.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ impl Cursor {
3737
slf
3838
}
3939

40+
/// Return next result from the SQL statement.
41+
///
42+
/// Execute FETCH <number> FROM <cursor name>
43+
///
44+
/// # Errors
45+
/// May return Err Result if can't execute querystring.
4046
pub fn __anext__(&self, py: Python<'_>) -> RustPSQLDriverPyResult<Option<PyObject>> {
4147
let db_client_arc = self.db_client.clone();
4248
let cursor_name = self.cursor_name.clone();

0 commit comments

Comments
 (0)