Так что я делаю < /p>
Код: Выделить всё
static POOL: Lazy
> = Lazy::new(|| {
let config = AsyncDieselConnectionManager::::new(
"mysql://[email protected]:3306/db",
);
Pool::builder(config).build().unwrap()
});
< /code>
Я получаю Conn, как < /p>
let mut conn = POOL.get().await?;
< /code>
Но мне нужен какой -то ввод (URL), поэтому я меняю ленивый, чтобы выйти из std :: sync < /p>
pub static POOL: OnceLock = OnceLock::new();
< /code>
Я пишу Fn, чтобы записать в oncelock < /p>
pub fn set_pool(db_url: &str) {
let pool = AsyncDieselConnectionManager::::new(db_url);
let conn = Pool::builder(pool).build().unwrap();
POOL.set(conn);
}
< /code>
Но когда я хочу получить значение,
я делаю то же самое, что и ленивый, но получаю < /p>
the trait bound `deadpool::managed::Pool: DerefMut` is not satisfied --> src/diesel.rs:512:18 | 512 | ... .execute(&mut conn) | ^^^^^^^ unsatisfied trait bound | = help: the trait `DerefMut` is not implemented for `Pool` = help: the following other types implement trait `AsyncConnection`: AsyncMysqlConnection AsyncPgConnection SyncConnectionWrapper = note: required for `Pool` to implement `AsyncConnection`
= note: the full name for the type has been written to '/data/data/com.termux/files/home/lucle/target/debug/deps/lucle-aa4e36718ce9a19c.long-type-4366048800889042929.txt' = note: consider using `--verbose` to print the full type name to the console
Подробнее здесь: https://stackoverflow.com/questions/795 ... -same-type