Description
Can't put rusqlite database connection objects in statics / globals because of compiler error:
static DB_LOCK: std::sync::OnceLock<DatabaseConnection> = OnceLock::new();
This cause
error[E0277]: `(dyn for<'a, 'b> Fn(&'a sea_orm::metric::Info<'b>) + 'static)` cannot be shared between threads safely
--> packages/storage_crackhouse/src/basic/mod.rs:115:17
|
115 | static DB_LOCK: std::sync::OnceLock<DatabaseConnection> = OnceLock::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `(dyn for<'a, 'b> Fn(&'a sea_orm::metric::Info<'b>) + 'static)` cannot be shared between threads safely
|
= help: the trait `Sync` is not implemented for `(dyn for<'a, 'b> Fn(&'a sea_orm::metric::Info<'b>) + 'static)`
= note: required for `Arc<(dyn for<'a, 'b> Fn(&'a sea_orm::metric::Info<'b>) + 'static)>` to implement `Sync`
note: required because it appears within the type `Option<Arc<(dyn for<'a, 'b> Fn(&'a sea_orm::metric::Info<'b>) + 'static)>>`
--> /home/p/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:600:10
|
600 | pub enum Option<T> {
| ^^^^^^
note: required because it appears within the type `sea_orm::driver::rusqlite::RusqliteSharedConnection`
--> /home/p/V/sea-orm/sea-orm-sync/src/driver/rusqlite.rs:42:12
|
42 | pub struct RusqliteSharedConnection {
| ^^^^^^^^^^^^^^^^^^^^^^^^
note: required because it appears within the type `DatabaseConnectionType`
--> /home/p/V/sea-orm/sea-orm-sync/src/database/db_connection.rs:34:10
|
34 | pub enum DatabaseConnectionType {
| ^^^^^^^^^^^^^^^^^^^^^^
note: required because it appears within the type `DatabaseConnection`
--> /home/p/V/sea-orm/sea-orm-sync/src/database/db_connection.rs:24:12
|
24 | pub struct DatabaseConnection {
| ^^^^^^^^^^^^^^^^^^
= note: required for `OnceLock<DatabaseConnection>` to implement `Sync`
= note: shared static variables must have a type that implements `Sync`
Steps to Reproduce
static DB_LOCK: std::sync::OnceLock<DatabaseConnection> = OnceLock::new();
- compiler error
-
Expected Behavior
compile
Actual Behavior
no compile
Reproduces How Often
always
Workarounds
diff --git a/sea-orm-sync/src/metric.rs b/sea-orm-sync/src/metric.rs
index 86bf48d6..6c37fe86 100644
--- a/sea-orm-sync/src/metric.rs
+++ b/sea-orm-sync/src/metric.rs
@@ -1,6 +1,6 @@
use std::{sync::Arc, time::Duration};
-pub(crate) type Callback = Arc<dyn Fn(&Info<'_>)>;
+pub(crate) type Callback = Arc<dyn Fn(&Info<'_>)+Send+Sync>;
#[allow(unused_imports)]
pub(crate) use inner::metric;
johnny-smitherson@e7492d9
Versions
same as #3068
Description
Can't put rusqlite database connection objects in statics / globals because of compiler error:
This cause
Steps to Reproduce
static DB_LOCK: std::sync::OnceLock<DatabaseConnection> = OnceLock::new();Expected Behavior
compile
Actual Behavior
no compile
Reproduces How Often
always
Workarounds
johnny-smitherson@e7492d9
Versions
same as #3068