From d80f21d7d8e8de96c99f42564442bed6ad6fd0b5 Mon Sep 17 00:00:00 2001 From: David Li Date: Thu, 22 Jan 2026 16:56:27 +0900 Subject: [PATCH] feat(rust/core)!: define cancellation in a sensible way Closes #3454. --- rust/core/src/sync.rs | 39 +++++++-- rust/driver/datafusion/src/lib.rs | 8 -- rust/driver/dummy/src/lib.rs | 32 +++---- .../dummy/tests/driver_exporter_dummy.rs | 22 +++-- rust/driver/snowflake/src/connection.rs | 4 +- rust/driver/snowflake/src/statement.rs | 4 +- rust/driver_manager/src/lib.rs | 84 +++++++++++++------ .../tests/driver_manager_sqlite.rs | 10 ++- rust/ffi/src/driver_exporter.rs | 52 +++++++++--- 9 files changed, 173 insertions(+), 82 deletions(-) diff --git a/rust/core/src/sync.rs b/rust/core/src/sync.rs index de26918b95..aaa4ab4888 100644 --- a/rust/core/src/sync.rs +++ b/rust/core/src/sync.rs @@ -44,6 +44,24 @@ pub trait Optionable { fn get_option_double(&self, key: Self::Option) -> Result; } +/// A handle to cancel an in-progress operation on a connection. +/// +/// This is a separated handle because otherwise it would be impossible to +/// call a `cancel` method on a connection or statement itself. +pub trait CancelHandle: Send { + /// Cancel the in-progress operation on a connection. + fn try_cancel(&self) -> Result<()>; +} + +/// A cancellation handle that does nothing (because cancellation is unsupported). +pub struct NoOpCancellationHandle; + +impl CancelHandle for NoOpCancellationHandle { + fn try_cancel(&self) -> Result<()> { + Ok(()) + } +} + /// A handle to an ADBC driver. pub trait Driver { type DatabaseType: Database; @@ -76,6 +94,11 @@ pub trait Database: Optionable