Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
mmastrac committed Feb 25, 2025
1 parent 3677e85 commit e025e33
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 25 deletions.
4 changes: 2 additions & 2 deletions rust/gel-http/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ mod tests {
);

let (state, body) = cache.get_cache_body(&uri).unwrap();
assert_eq!(state, true);
assert!(state);
assert_eq!(body, "contents!".as_bytes());

let (method, uri, headers, body) = get_google();
Expand Down Expand Up @@ -334,7 +334,7 @@ mod tests {
);

let (state, body) = cache.get_cache_body(&uri).unwrap();
assert_eq!(state, true);
assert!(state);
assert_eq!(body, "contents!".as_bytes());
}
}
2 changes: 1 addition & 1 deletion rust/gel-jwt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ mod tests {
// With no claim validation, the token should be valid
let res = registry.validate(&token, &validation_ctx);
assert!(
matches!(res, Ok(_)),
res.is_ok(),
"{}",
res.unwrap_err().error_string_not_for_user()
);
Expand Down
8 changes: 2 additions & 6 deletions rust/gel-stream/src/common/openssl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,8 @@ struct HandshakeData {

impl HandshakeData {
fn from_ssl(ssl: &SslRef) -> Option<MutexGuard<Self>> {
let Some(handshake) = ssl.ex_data(get_ssl_ex_data_index()) else {
return None;
};
let Ok(handshake) = handshake.lock() else {
return None;
};
let handshake = ssl.ex_data(get_ssl_ex_data_index())?;
let handshake = handshake.lock().ok()?;
Some(handshake)
}
}
Expand Down
7 changes: 0 additions & 7 deletions rust/pgrust/src/python/async_connector.rs

This file was deleted.

2 changes: 0 additions & 2 deletions rust/pgrust/src/python/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ use std::collections::HashMap;
use std::{borrow::Cow, path::Path};
use tracing::warn;

mod async_connector;

#[derive(Clone, Copy, PartialEq, Eq)]
#[pyclass(eq, eq_int)]
pub enum SSLMode {
Expand Down
19 changes: 12 additions & 7 deletions rust/pyo3_util/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ pub struct RustChannel<RX: for<'py> FromPyObject<'py>, TX: for<'py> IntoPyObject

impl<RX: PythonToRust, TX: RustToPython> RustChannel<RX, TX> {
pub async fn recv(&self) -> Option<RX> {
let msg = self.python_to_rust.borrow_mut().recv().await;
msg
// Don't hold the lock across the await point
poll_fn(|cx| {
let pipe = &mut *self.python_to_rust.borrow_mut();
let mut this = Pin::new(pipe);
this.poll_recv(cx)
})
.await
}

pub async fn write(&self, msg: TX) -> Result<(), String> {
Expand Down Expand Up @@ -72,15 +77,15 @@ impl<RX: PythonToRust, TX: RustToPython> PythonChannelImpl<RX, TX> {
}

pub trait PythonChannelProtocol: Send + Sync {
fn _write<'py>(&self, py: Python<'py>, msg: Py<PyAny>) -> PyResult<()>;
fn _write(&self, py: Python<'_>, msg: Py<PyAny>) -> PyResult<()>;
fn _read<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyAny>>;
fn _try_read<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyAny>>;
fn _close_pipe(&mut self) -> ();
fn _close_pipe(&mut self);
fn _fd(&self) -> u64;
}

impl<RX: PythonToRust, TX: RustToPython> PythonChannelProtocol for Arc<PythonChannelImpl<RX, TX>> {
fn _write<'py>(&self, py: Python<'py>, msg: Py<PyAny>) -> PyResult<()> {
fn _write(&self, py: Python<'_>, msg: Py<PyAny>) -> PyResult<()> {
let msg = msg.extract(py)?;
trace!("Python -> Rust: {msg:?}");
self.python_to_rust
Expand Down Expand Up @@ -121,7 +126,7 @@ impl<RX: PythonToRust, TX: RustToPython> PythonChannelProtocol for Arc<PythonCha
.into_any())
}

fn _close_pipe(&mut self) -> () {
fn _close_pipe(&mut self) {
*self
.rust_to_python
.try_lock()
Expand All @@ -148,7 +153,7 @@ impl PythonChannel {

#[pymethods]
impl PythonChannel {
fn _write<'py>(&self, py: Python<'py>, msg: Py<PyAny>) -> PyResult<()> {
fn _write(&self, py: Python<'_>, msg: Py<PyAny>) -> PyResult<()> {
self._impl._write(py, msg)
}

Expand Down

0 comments on commit e025e33

Please sign in to comment.