From 78107935b536dae3acd3ac2d0f4036aaa0355691 Mon Sep 17 00:00:00 2001 From: pedrocarlo Date: Mon, 30 Jun 2025 15:22:48 -0300 Subject: [PATCH] clippy --- bindings/rust/src/lib.rs | 2 +- bindings/rust/src/row.rs | 76 +++++++++++++++++++--------------------- stress/main.rs | 3 +- 3 files changed, 39 insertions(+), 42 deletions(-) diff --git a/bindings/rust/src/lib.rs b/bindings/rust/src/lib.rs index 8ba309502..315583bf3 100644 --- a/bindings/rust/src/lib.rs +++ b/bindings/rust/src/lib.rs @@ -66,7 +66,7 @@ impl From for Error { pub(crate) type BoxError = Box; -pub(crate) type Result = std::result::Result; +pub type Result = std::result::Result; /// A builder for `Database`. pub struct Builder { diff --git a/bindings/rust/src/row.rs b/bindings/rust/src/row.rs index 10dedc77c..6a631c670 100644 --- a/bindings/rust/src/row.rs +++ b/bindings/rust/src/row.rs @@ -1,5 +1,6 @@ use std::sync::{Arc, Mutex}; +use crate::Error; use crate::Value; /// Results of a prepared statement query. @@ -23,7 +24,6 @@ unsafe impl Sync for Rows {} impl Rows { /// Fetch the next row of this result set. pub async fn next(&mut self) -> crate::Result> { - use crate::Error; loop { let mut stmt = self .inner @@ -64,48 +64,44 @@ impl futures_util::Stream for Rows { self: std::pin::Pin<&mut Self>, _cx: &mut std::task::Context<'_>, ) -> std::task::Poll> { - use crate::Error; use std::task::Poll; - loop { - let stmt = self - .inner - .lock() - .map_err(|e| Error::MutexError(e.to_string())); + let stmt = self + .inner + .lock() + .map_err(|e| Error::MutexError(e.to_string())); - if let Err(err) = stmt { - return Poll::Ready(Some(Err(err))); - } - let mut stmt = stmt.unwrap(); - match stmt.step() { - Ok(step_result) => match step_result { - turso_core::StepResult::Row => { - let row = stmt.row().unwrap(); - return Poll::Ready(Some(Ok(Row { - values: row.get_values().map(|v| v.to_owned()).collect(), - }))); - } - turso_core::StepResult::Done => { - stmt.reset(); - return Poll::Ready(None); - } - turso_core::StepResult::IO => { - if let Err(e) = stmt.run_once() { - return Poll::Ready(Some(Err(e.into()))); - } - // TODO: see correct way to signal for this task to wake up - return Poll::Pending; - } - // TODO: Busy and Interrupt should probably return errors - turso_core::StepResult::Busy | turso_core::StepResult::Interrupt => { - stmt.reset(); - return Poll::Ready(None); - } - }, - Err(err) => { - use crate::Error; - stmt.reset(); - return Poll::Ready(Some(Err(Error::from(err)))); + if let Err(err) = stmt { + return Poll::Ready(Some(Err(err))); + } + let mut stmt = stmt.unwrap(); + match stmt.step() { + Ok(step_result) => match step_result { + turso_core::StepResult::Row => { + let row = stmt.row().unwrap(); + Poll::Ready(Some(Ok(Row { + values: row.get_values().map(|v| v.to_owned()).collect(), + }))) } + turso_core::StepResult::Done => { + stmt.reset(); + Poll::Ready(None) + } + turso_core::StepResult::IO => { + if let Err(e) = stmt.run_once() { + return Poll::Ready(Some(Err(e.into()))); + } + // TODO: see correct way to signal for this task to wake up + Poll::Pending + } + // TODO: Busy and Interrupt should probably return errors + turso_core::StepResult::Busy | turso_core::StepResult::Interrupt => { + stmt.reset(); + Poll::Ready(None) + } + }, + Err(err) => { + stmt.reset(); + Poll::Ready(Some(Err(Error::from(err)))) } } } diff --git a/stress/main.rs b/stress/main.rs index d4807fbad..3cd61016a 100644 --- a/stress/main.rs +++ b/stress/main.rs @@ -15,6 +15,7 @@ use tracing_appender::non_blocking::WorkerGuard; use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::util::SubscriberInitExt; use tracing_subscriber::EnvFilter; +use turso::futures_util::TryStreamExt; use turso::Builder; pub struct Plan { @@ -522,7 +523,7 @@ async fn main() -> Result<(), Box> { const INTEGRITY_CHECK_INTERVAL: usize = 100; if query_index % INTEGRITY_CHECK_INTERVAL == 0 { let mut res = conn.query("PRAGMA integrity_check", ()).await.unwrap(); - if let Some(row) = res.next().await? { + if let Some(row) = res.try_next().await? { let value = row.get_value(0).unwrap(); if value != "ok".into() { panic!("integrity check failed: {:?}", value);