在rust中将同步闭包移植到异步闭包时的生存期问题

4urapxun  于 2021-06-10  发布在  Redis
关注(0)|答案(0)|浏览(283)

我目前正在尝试将一些使用redis板条箱和redis事务的生 rust 代码从同步代码移植到异步代码,并遇到一些问题(目前与生存期相关,但根本原因可能在端口的其他地方)。
这两种情况下的代码在中都使用以下依赖项 Cargo.toml :

  1. [dependencies]
  2. redis = "0.16"
  3. tokio = { version = "0.2", features = ["full"] }

工作同步代码的最小示例如下所示:

  1. use redis::{pipe, cmd, Pipeline, ToRedisArgs, RedisResult};
  2. fn main() -> RedisResult<()> {
  3. let client = redis::Client::open("redis://127.0.0.1/").unwrap();
  4. let mut sync_conn = client.get_connection()?;
  5. let key = "foo";
  6. let (val,): (u32,) = transaction(&mut sync_conn, &[key], |conn, pipe| {
  7. pipe.set(key, 1)
  8. .ignore()
  9. .get(key)
  10. .query(conn)
  11. })?;
  12. println!("val: {}", val);
  13. Ok(())
  14. }
  15. fn transaction<
  16. C: redis::ConnectionLike,
  17. K: ToRedisArgs,
  18. T,
  19. F: FnMut(&mut C, &mut Pipeline) -> RedisResult<Option<T>>,
  20. >(
  21. con: &mut C,
  22. keys: &[K],
  23. func: F,
  24. ) -> RedisResult<T> {
  25. let mut func = func;
  26. loop {
  27. cmd("WATCH").arg(keys).query(con)?;
  28. if let Some(response) = func(con, pipe().atomic())? {
  29. cmd("UNWATCH").query(con)?;
  30. return Ok(response);
  31. }
  32. }
  33. }

我尝试将此代码转换为异步代码,如下所示:

  1. use redis::{AsyncCommands, pipe, cmd, Pipeline, ToRedisArgs, RedisResult, aio::ConnectionLike};
  2. use std::future::Future;
  3. # [tokio::main]
  4. async fn main() -> RedisResult<()> {
  5. let client = redis::Client::open("redis://127.0.0.1/").unwrap();
  6. let mut async_conn = client.get_async_connection().await?;
  7. let key = "foo";
  8. let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  9. pipe.set(key, 1)
  10. .ignore()
  11. .get(key)
  12. .query_async(conn).await
  13. }).await?;
  14. println!("val: {}", val);
  15. Ok(())
  16. }
  17. pub async fn async_transaction<
  18. C: ConnectionLike + Send,
  19. K: ToRedisArgs,
  20. T,
  21. F: FnMut(&mut C, &mut Pipeline) -> Fut,
  22. Fut: Future<Output = RedisResult<Option<T>>>,
  23. >(
  24. con: & mut C,
  25. keys: &[K],
  26. func: F,
  27. ) -> RedisResult<T> {
  28. let mut func = func;
  29. loop {
  30. cmd("WATCH").arg(keys).query_async(con).await?;
  31. if let Some(response) = func(con, pipe().atomic()).await? {
  32. cmd("UNWATCH").query_async(con).await?;
  33. return Ok(response);
  34. }
  35. }
  36. }

主要的变化是使用异步连接、使用async/await和 query_async 而不是 query . 另一个主要的变化是传递给 async_transaction 返回 Future 而不是直接的结果。
但是,试图编译此文件会导致19个错误(它们大多是基于生命周期的):

  1. error[E0486]: type of expression contains references that are not valid during the expression: `for<'_, '_> fn(&mut redis::aio::Connection, &[&str], [closure@src/main.rs:11:69: 16:6 key:&&str]) -> impl std::future::Future {async_transaction::<redis::aio::Connection, &str, (u32,), [closure@src/main.rs:11:69: 16:6 key:&&str], impl std::future::Future>}`
  2. --> src/main.rs:11:26
  3. |
  4. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  5. | ^^^^^^^^^^^^^^^^^
  6. |
  7. note: type is only valid for the anonymous lifetime #2 defined on the body at 11:69
  8. --> src/main.rs:11:69
  9. |
  10. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  11. | _____________________________________________________________________^
  12. 12 | | pipe.set(key, 1)
  13. 13 | | .ignore()
  14. 14 | | .get(key)
  15. 15 | | .query_async(conn).await
  16. 16 | | }).await?;
  17. | |_____^
  18. error[E0486]: type of expression contains references that are not valid during the expression: `for<'_, '_> fn(&mut redis::aio::Connection, &[&str], [closure@src/main.rs:11:69: 16:6 key:&&str]) -> impl std::future::Future {async_transaction::<redis::aio::Connection, &str, (u32,), [closure@src/main.rs:11:69: 16:6 key:&&str], impl std::future::Future>}`
  19. --> src/main.rs:11:26
  20. |
  21. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  22. | ^^^^^^^^^^^^^^^^^
  23. |
  24. note: type is only valid for the anonymous lifetime #3 defined on the body at 11:69
  25. --> src/main.rs:11:69
  26. |
  27. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  28. | _____________________________________________________________________^
  29. 12 | | pipe.set(key, 1)
  30. 13 | | .ignore()
  31. 14 | | .get(key)
  32. 15 | | .query_async(conn).await
  33. 16 | | }).await?;
  34. | |_____^
  35. error[E0486]: type of expression contains references that are not valid during the expression: `impl std::future::Future`
  36. --> src/main.rs:11:26
  37. |
  38. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  39. | __________________________^
  40. 12 | | pipe.set(key, 1)
  41. 13 | | .ignore()
  42. 14 | | .get(key)
  43. 15 | | .query_async(conn).await
  44. 16 | | }).await?;
  45. | |______^
  46. |
  47. note: type is only valid for the anonymous lifetime #2 defined on the body at 11:69
  48. --> src/main.rs:11:69
  49. |
  50. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  51. | _____________________________________________________________________^
  52. 12 | | pipe.set(key, 1)
  53. 13 | | .ignore()
  54. 14 | | .get(key)
  55. 15 | | .query_async(conn).await
  56. 16 | | }).await?;
  57. | |_____^
  58. error[E0486]: type of expression contains references that are not valid during the expression: `impl std::future::Future`
  59. --> src/main.rs:11:26
  60. |
  61. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  62. | __________________________^
  63. 12 | | pipe.set(key, 1)
  64. 13 | | .ignore()
  65. 14 | | .get(key)
  66. 15 | | .query_async(conn).await
  67. 16 | | }).await?;
  68. | |______^
  69. |
  70. note: type is only valid for the anonymous lifetime #3 defined on the body at 11:69
  71. --> src/main.rs:11:69
  72. |
  73. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  74. | _____________________________________________________________________^
  75. 12 | | pipe.set(key, 1)
  76. 13 | | .ignore()
  77. 14 | | .get(key)
  78. 15 | | .query_async(conn).await
  79. 16 | | }).await?;
  80. | |_____^
  81. error[E0486]: type of expression contains references that are not valid during the expression: `impl std::future::Future`
  82. --> src/main.rs:11:26
  83. |
  84. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  85. | __________________________^
  86. 12 | | pipe.set(key, 1)
  87. 13 | | .ignore()
  88. 14 | | .get(key)
  89. 15 | | .query_async(conn).await
  90. 16 | | }).await?;
  91. | |____________^
  92. |
  93. note: type is only valid for the anonymous lifetime #2 defined on the body at 11:69
  94. --> src/main.rs:11:69
  95. |
  96. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  97. | _____________________________________________________________________^
  98. 12 | | pipe.set(key, 1)
  99. 13 | | .ignore()
  100. 14 | | .get(key)
  101. 15 | | .query_async(conn).await
  102. 16 | | }).await?;
  103. | |_____^
  104. error[E0486]: type of expression contains references that are not valid during the expression: `impl std::future::Future`
  105. --> src/main.rs:11:26
  106. |
  107. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  108. | __________________________^
  109. 12 | | pipe.set(key, 1)
  110. 13 | | .ignore()
  111. 14 | | .get(key)
  112. 15 | | .query_async(conn).await
  113. 16 | | }).await?;
  114. | |____________^
  115. |
  116. note: type is only valid for the anonymous lifetime #3 defined on the body at 11:69
  117. --> src/main.rs:11:69
  118. |
  119. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  120. | _____________________________________________________________________^
  121. 12 | | pipe.set(key, 1)
  122. 13 | | .ignore()
  123. 14 | | .get(key)
  124. 15 | | .query_async(conn).await
  125. 16 | | }).await?;
  126. | |_____^
  127. error[E0486]: type of expression contains references that are not valid during the expression: `&mut impl std::future::Future`
  128. --> src/main.rs:11:26
  129. |
  130. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  131. | __________________________^
  132. 12 | | pipe.set(key, 1)
  133. 13 | | .ignore()
  134. 14 | | .get(key)
  135. 15 | | .query_async(conn).await
  136. 16 | | }).await?;
  137. | |____________^
  138. |
  139. note: type is only valid for the anonymous lifetime #2 defined on the body at 11:69
  140. --> src/main.rs:11:69
  141. |
  142. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  143. | _____________________________________________________________________^
  144. 12 | | pipe.set(key, 1)
  145. 13 | | .ignore()
  146. 14 | | .get(key)
  147. 15 | | .query_async(conn).await
  148. 16 | | }).await?;
  149. | |_____^
  150. error[E0486]: type of expression contains references that are not valid during the expression: `&mut impl std::future::Future`
  151. --> src/main.rs:11:26
  152. |
  153. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  154. | __________________________^
  155. 12 | | pipe.set(key, 1)
  156. 13 | | .ignore()
  157. 14 | | .get(key)
  158. 15 | | .query_async(conn).await
  159. 16 | | }).await?;
  160. | |____________^
  161. |
  162. note: type is only valid for the anonymous lifetime #3 defined on the body at 11:69
  163. --> src/main.rs:11:69
  164. |
  165. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  166. | _____________________________________________________________________^
  167. 12 | | pipe.set(key, 1)
  168. 13 | | .ignore()
  169. 14 | | .get(key)
  170. 15 | | .query_async(conn).await
  171. 16 | | }).await?;
  172. | |_____^
  173. error[E0486]: type of expression contains references that are not valid during the expression: `unsafe fn(&mut impl std::future::Future) -> std::pin::Pin<&mut impl std::future::Future> {std::pin::Pin::<&mut impl std::future::Future>::new_unchecked}`
  174. --> src/main.rs:11:26
  175. |
  176. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  177. | __________________________^
  178. 12 | | pipe.set(key, 1)
  179. 13 | | .ignore()
  180. 14 | | .get(key)
  181. 15 | | .query_async(conn).await
  182. 16 | | }).await?;
  183. | |____________^
  184. |
  185. note: type is only valid for the anonymous lifetime #2 defined on the body at 11:69
  186. --> src/main.rs:11:69
  187. |
  188. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  189. | _____________________________________________________________________^
  190. 12 | | pipe.set(key, 1)
  191. 13 | | .ignore()
  192. 14 | | .get(key)
  193. 15 | | .query_async(conn).await
  194. 16 | | }).await?;
  195. | |_____^
  196. error[E0486]: type of expression contains references that are not valid during the expression: `unsafe fn(&mut impl std::future::Future) -> std::pin::Pin<&mut impl std::future::Future> {std::pin::Pin::<&mut impl std::future::Future>::new_unchecked}`
  197. --> src/main.rs:11:26
  198. |
  199. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  200. | __________________________^
  201. 12 | | pipe.set(key, 1)
  202. 13 | | .ignore()
  203. 14 | | .get(key)
  204. 15 | | .query_async(conn).await
  205. 16 | | }).await?;
  206. | |____________^
  207. |
  208. note: type is only valid for the anonymous lifetime #3 defined on the body at 11:69
  209. --> src/main.rs:11:69
  210. |
  211. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  212. | _____________________________________________________________________^
  213. 12 | | pipe.set(key, 1)
  214. 13 | | .ignore()
  215. 14 | | .get(key)
  216. 15 | | .query_async(conn).await
  217. 16 | | }).await?;
  218. | |_____^
  219. error[E0486]: type of expression contains references that are not valid during the expression: `std::pin::Pin<&mut impl std::future::Future>`
  220. --> src/main.rs:11:26
  221. |
  222. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  223. | __________________________^
  224. 12 | | pipe.set(key, 1)
  225. 13 | | .ignore()
  226. 14 | | .get(key)
  227. 15 | | .query_async(conn).await
  228. 16 | | }).await?;
  229. | |____________^
  230. |
  231. note: type is only valid for the anonymous lifetime #2 defined on the body at 11:69
  232. --> src/main.rs:11:69
  233. |
  234. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  235. | _____________________________________________________________________^
  236. 12 | | pipe.set(key, 1)
  237. 13 | | .ignore()
  238. 14 | | .get(key)
  239. 15 | | .query_async(conn).await
  240. 16 | | }).await?;
  241. | |_____^
  242. error[E0486]: type of expression contains references that are not valid during the expression: `std::pin::Pin<&mut impl std::future::Future>`
  243. --> src/main.rs:11:26
  244. |
  245. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  246. | __________________________^
  247. 12 | | pipe.set(key, 1)
  248. 13 | | .ignore()
  249. 14 | | .get(key)
  250. 15 | | .query_async(conn).await
  251. 16 | | }).await?;
  252. | |____________^
  253. |
  254. note: type is only valid for the anonymous lifetime #3 defined on the body at 11:69
  255. --> src/main.rs:11:69
  256. |
  257. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  258. | _____________________________________________________________________^
  259. 12 | | pipe.set(key, 1)
  260. 13 | | .ignore()
  261. 14 | | .get(key)
  262. 15 | | .query_async(conn).await
  263. 16 | | }).await?;
  264. | |_____^
  265. error[E0486]: type of expression contains references that are not valid during the expression: `for<'r, 's, 't0> fn(std::pin::Pin<&'r mut impl std::future::Future>, &'s mut std::task::Context<'t0>) -> std::task::Poll<<impl std::future::Future as std::future::Future>::Output> {<impl std::future::Future as std::future::Future>::poll}`
  266. --> src/main.rs:11:26
  267. |
  268. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  269. | __________________________^
  270. 12 | | pipe.set(key, 1)
  271. 13 | | .ignore()
  272. 14 | | .get(key)
  273. 15 | | .query_async(conn).await
  274. 16 | | }).await?;
  275. | |____________^
  276. |
  277. note: type is only valid for the anonymous lifetime #2 defined on the body at 11:69
  278. --> src/main.rs:11:69
  279. |
  280. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  281. | _____________________________________________________________________^
  282. 12 | | pipe.set(key, 1)
  283. 13 | | .ignore()
  284. 14 | | .get(key)
  285. 15 | | .query_async(conn).await
  286. 16 | | }).await?;
  287. | |_____^
  288. error[E0486]: type of expression contains references that are not valid during the expression: `for<'r, 's, 't0> fn(std::pin::Pin<&'r mut impl std::future::Future>, &'s mut std::task::Context<'t0>) -> std::task::Poll<<impl std::future::Future as std::future::Future>::Output> {<impl std::future::Future as std::future::Future>::poll}`
  289. --> src/main.rs:11:26
  290. |
  291. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  292. | __________________________^
  293. 12 | | pipe.set(key, 1)
  294. 13 | | .ignore()
  295. 14 | | .get(key)
  296. 15 | | .query_async(conn).await
  297. 16 | | }).await?;
  298. | |____________^
  299. |
  300. note: type is only valid for the anonymous lifetime #3 defined on the body at 11:69
  301. --> src/main.rs:11:69
  302. |
  303. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  304. | _____________________________________________________________________^
  305. 12 | | pipe.set(key, 1)
  306. 13 | | .ignore()
  307. 14 | | .get(key)
  308. 15 | | .query_async(conn).await
  309. 16 | | }).await?;
  310. | |_____^
  311. error[E0481]: lifetime of function argument does not outlive the function call
  312. --> src/main.rs:11:26
  313. |
  314. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  315. | __________________________^
  316. 12 | | pipe.set(key, 1)
  317. 13 | | .ignore()
  318. 14 | | .get(key)
  319. 15 | | .query_async(conn).await
  320. 16 | | }).await?;
  321. | |____________^
  322. |
  323. note: the function argument is only valid for the anonymous lifetime #2 defined on the body at 11:69
  324. --> src/main.rs:11:69
  325. |
  326. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  327. | _____________________________________________________________________^
  328. 12 | | pipe.set(key, 1)
  329. 13 | | .ignore()
  330. 14 | | .get(key)
  331. 15 | | .query_async(conn).await
  332. 16 | | }).await?;
  333. | |_____^
  334. error[E0481]: lifetime of function argument does not outlive the function call
  335. --> src/main.rs:11:26
  336. |
  337. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  338. | __________________________^
  339. 12 | | pipe.set(key, 1)
  340. 13 | | .ignore()
  341. 14 | | .get(key)
  342. 15 | | .query_async(conn).await
  343. 16 | | }).await?;
  344. | |____________^
  345. |
  346. note: the function argument is only valid for the anonymous lifetime #3 defined on the body at 11:69
  347. --> src/main.rs:11:69
  348. |
  349. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  350. | _____________________________________________________________________^
  351. 12 | | pipe.set(key, 1)
  352. 13 | | .ignore()
  353. 14 | | .get(key)
  354. 15 | | .query_async(conn).await
  355. 16 | | }).await?;
  356. | |_____^
  357. error[E0488]: lifetime of variable does not enclose its declaration
  358. --> src/main.rs:11:26
  359. |
  360. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  361. | __________________________^
  362. 12 | | pipe.set(key, 1)
  363. 13 | | .ignore()
  364. 14 | | .get(key)
  365. 15 | | .query_async(conn).await
  366. 16 | | }).await?;
  367. | |____________^
  368. |
  369. note: the variable is only valid for the anonymous lifetime #2 defined on the body at 11:69
  370. --> src/main.rs:11:69
  371. |
  372. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  373. | _____________________________________________________________________^
  374. 12 | | pipe.set(key, 1)
  375. 13 | | .ignore()
  376. 14 | | .get(key)
  377. 15 | | .query_async(conn).await
  378. 16 | | }).await?;
  379. | |_____^
  380. error[E0488]: lifetime of variable does not enclose its declaration
  381. --> src/main.rs:11:26
  382. |
  383. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  384. | __________________________^
  385. 12 | | pipe.set(key, 1)
  386. 13 | | .ignore()
  387. 14 | | .get(key)
  388. 15 | | .query_async(conn).await
  389. 16 | | }).await?;
  390. | |____________^
  391. |
  392. note: the variable is only valid for the anonymous lifetime #3 defined on the body at 11:69
  393. --> src/main.rs:11:69
  394. |
  395. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  396. | _____________________________________________________________________^
  397. 12 | | pipe.set(key, 1)
  398. 13 | | .ignore()
  399. 14 | | .get(key)
  400. 15 | | .query_async(conn).await
  401. 16 | | }).await?;
  402. | |_____^
  403. error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
  404. --> src/main.rs:11:26
  405. |
  406. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  407. | __________________________^
  408. 12 | | pipe.set(key, 1)
  409. 13 | | .ignore()
  410. 14 | | .get(key)
  411. 15 | | .query_async(conn).await
  412. 16 | | }).await?;
  413. | |____________^
  414. |
  415. note: first, the lifetime cannot outlive the anonymous lifetime #3 defined on the body at 11:69...
  416. --> src/main.rs:11:69
  417. |
  418. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  419. | _____________________________________________________________________^
  420. 12 | | pipe.set(key, 1)
  421. 13 | | .ignore()
  422. 14 | | .get(key)
  423. 15 | | .query_async(conn).await
  424. 16 | | }).await?;
  425. | |_____^
  426. note: ...so that the type `impl std::future::Future` is not borrowed for too long
  427. --> src/main.rs:11:26
  428. |
  429. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  430. | __________________________^
  431. 12 | | pipe.set(key, 1)
  432. 13 | | .ignore()
  433. 14 | | .get(key)
  434. 15 | | .query_async(conn).await
  435. 16 | | }).await?;
  436. | |____________^
  437. note: but, the lifetime must be valid for the call at 11:26...
  438. --> src/main.rs:11:26
  439. |
  440. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  441. | __________________________^
  442. 12 | | pipe.set(key, 1)
  443. 13 | | .ignore()
  444. 14 | | .get(key)
  445. 15 | | .query_async(conn).await
  446. 16 | | }).await?;
  447. | |____________^
  448. note: ...so that argument is valid for the call
  449. --> src/main.rs:11:26
  450. |
  451. 11 | let (val,): (u32,) = async_transaction(&mut async_conn, &[key], |conn, pipe| async {
  452. | __________________________^
  453. 12 | | pipe.set(key, 1)
  454. 13 | | .ignore()
  455. 14 | | .get(key)
  456. 15 | | .query_async(conn).await
  457. 16 | | }).await?;
  458. | |____________^
  459. error: aborting due to 19 previous errors
  460. For more information about this error, try `rustc --explain E0495`.
  461. error: could not compile `redistest`.
  462. To learn more, run the command again with --verbose.

我是否可以应用一些生命周期注解来解决这个问题,或者在这种情况下,我应该做些其他的事情来从同步代码转移到异步代码?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题