From c7803712e9f0e88f0cd30830f3011cd6f2d56ff6 Mon Sep 17 00:00:00 2001 From: Andrew Plaza Date: Wed, 24 Jul 2024 16:10:11 -0400 Subject: [PATCH 1/2] opt out of `Send` for wasm32 --- src/lib.rs | 6 ++++-- src/run_query_dsl/mod.rs | 6 ++++-- src/stmt_cache.rs | 3 ++- src/transaction_manager.rs | 6 ++++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index db532b0..8698023 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -115,7 +115,8 @@ pub use self::transaction_manager::{AnsiTransactionManager, TransactionManager}; /// Perform simple operations on a backend. /// /// You should likely use [`AsyncConnection`] instead. -#[async_trait::async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)] pub trait SimpleAsyncConnection { /// Execute multiple SQL statements within the same string. /// @@ -129,7 +130,8 @@ pub trait SimpleAsyncConnection { /// This trait represents a n async database connection. It can be used to query the database through /// the query dsl provided by diesel, custom extensions or raw sql queries. It essentially mirrors /// the sync diesel [`Connection`](diesel::connection::Connection) implementation -#[async_trait::async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)] pub trait AsyncConnection: SimpleAsyncConnection + Sized + Send { /// The future returned by `AsyncConnection::execute` type ExecuteFuture<'conn, 'query>: Future> + Send; diff --git a/src/run_query_dsl/mod.rs b/src/run_query_dsl/mod.rs index f3767ee..a29b2fa 100644 --- a/src/run_query_dsl/mod.rs +++ b/src/run_query_dsl/mod.rs @@ -695,7 +695,8 @@ impl RunQueryDsl for T {} /// # Ok(()) /// # } /// ``` -#[async_trait::async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)] pub trait SaveChangesDsl { /// See the trait documentation async fn save_changes(self, connection: &mut Conn) -> QueryResult @@ -722,7 +723,8 @@ impl SaveChangesDsl for T where /// For implementing this trait for a custom backend: /// * The `Changes` generic parameter represents the changeset that should be stored /// * The `Output` generic parameter represents the type of the response. -#[async_trait::async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)] pub trait UpdateAndFetchResults: AsyncConnection where Changes: diesel::prelude::Identifiable + HasTable, diff --git a/src/stmt_cache.rs b/src/stmt_cache.rs index 9d6b9af..a6c6703 100644 --- a/src/stmt_cache.rs +++ b/src/stmt_cache.rs @@ -18,7 +18,8 @@ type PrepareFuture<'a, F, S> = future::Either< future::BoxFuture<'a, QueryResult<(MaybeCached<'a, S>, F)>>, >; -#[async_trait::async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)] pub trait PrepareCallback: Sized { async fn prepare( self, diff --git a/src/transaction_manager.rs b/src/transaction_manager.rs index cedb450..a84aeab 100644 --- a/src/transaction_manager.rs +++ b/src/transaction_manager.rs @@ -16,7 +16,8 @@ use crate::AsyncConnection; /// /// You will not need to interact with this trait, unless you are writing an /// implementation of [`AsyncConnection`]. -#[async_trait::async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)] pub trait TransactionManager: Send { /// Data stored as part of the connection implementation /// to track the current transaction state of a connection @@ -287,7 +288,8 @@ impl AnsiTransactionManager { } } -#[async_trait::async_trait] +#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)] impl TransactionManager for AnsiTransactionManager where Conn: AsyncConnection, From c255cddfecec3597fb102cfa85494f6e23cb6b9b Mon Sep 17 00:00:00 2001 From: Andrew Plaza Date: Wed, 24 Jul 2024 16:51:26 -0400 Subject: [PATCH 2/2] fix error on beta --- src/pooled_connection/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pooled_connection/mod.rs b/src/pooled_connection/mod.rs index 2ff16cf..3a8220a 100644 --- a/src/pooled_connection/mod.rs +++ b/src/pooled_connection/mod.rs @@ -293,6 +293,7 @@ where } } +#[allow(dead_code)] #[derive(diesel::query_builder::QueryId)] struct CheckConnectionQuery;