diff --git a/rust/core/src/sync.rs b/rust/core/src/sync.rs index de26918b95..d7f271da4e 100644 --- a/rust/core/src/sync.rs +++ b/rust/core/src/sync.rs @@ -20,7 +20,7 @@ use std::collections::HashSet; use arrow_array::{RecordBatch, RecordBatchReader}; use arrow_schema::Schema; -use crate::error::Result; +use crate::error::{Error, Result, Status}; use crate::options::{self, OptionConnection, OptionDatabase, OptionStatement, OptionValue}; use crate::PartitionedResult; @@ -44,6 +44,28 @@ pub trait Optionable { fn get_option_double(&self, key: Self::Option) -> Result; } +/// A handle to cancel an in-progress operation. +/// +/// This is a separated handle because otherwise it would be impossible to +/// safely call a `cancel` method on a database/connection/statement itself +/// due to the borrow checker. +pub trait CancelHandle: Send + Sync { + /// Attempt to cancel the in-progress operation (best-effort). + 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<()> { + Err(Error::with_message_and_status( + "cancellation not implemented", + Status::Unknown, + )) + } +} + /// A handle to an ADBC driver. pub trait Driver { type DatabaseType: Database; @@ -76,6 +98,11 @@ pub trait Database: Optionable