rust 当我只为sqlx和axum-database-sessions指定了一个运行时时,为什么会出现“only one runtime can be active”错误?

y0u0uwnf  于 2023-10-20  发布在  其他
关注(0)|答案(1)|浏览(161)

从Cargo.toml:

[package]
name = "sitegen"
version = "0.2.0"
edition = "2021"

[dependencies]
axum_database_sessions = { version = "5.0", features = [ "mysql-native"] }
sqlx = { version = "0.6", features = ["runtime-tokio-rustls", "mysql"] }
tokio = { version = "1.0", features = ["full"] }

编译错误:

error: only one of ['runtime-actix-native-tls', 'runtime-async-std-native-tls', 'runtime-tokio-native-tls', 'runtime-actix-rustls', 'runtime-async-std-rustls', 'runtime-tokio-rustls'] can be enabled
 --> /home/dsrich/.cargo/registry/src/github.com-1ecc6299db9ec823/sqlx-rt-0.6.2/src/lib.rs:23:1
  |
23 | / compile_error!(
24 | |     "only one of ['runtime-actix-native-tls', 'runtime-async-std-native-tls', \
25 | |      'runtime-tokio-native-tls', 'runtime-actix-rustls', 'runtime-async-std-rustls', \
26 | |      'runtime-tokio-rustls'] can be enabled"
27 | | );
  | |_^

error: could not compile `sqlx-rt` due to previous error

我在Linux上使用最新的rust x86-64,MySQL,在Cargo.toml中是否存在rustls没有区别。有什么建议吗?对我来说毫无意义...
只是试图编译它开始使用它与axum-sessions

gijlo24d

gijlo24d1#

axum_database_session的默认功能是["postgres-rustls"],因此如果你想使用*-native,你必须禁用默认功能:

axum_database_sessions = { version = "5.0", default-features = false, features = ["mysql-native"] }

但是由于你在sqlx的依赖项中显式地包含了rustls,你可能只想使用mysql-rustls,仍然没有默认功能,因为你使用的是MySQL而不是PostgreSQL:

axum_database_sessions = { version = "5.0", default-features = false, features = ["mysql-rustls"] }

相关问题