关于 闭包的相关问题

💡 原文中文,约14600字,阅读约需35分钟。
📝

内容提要

本文介绍了使用 actix_web 时的重构问题,第三次重构时出现类型不匹配的报错,主要原因是 router 放到外面后,app 的类型从 Fn 变为了 FnOnce,而 HttpServer::new() 只接受 Fn。

🎯

关键要点

  • 使用 actix_web 时遇到重构问题
  • 第三次重构时出现类型不匹配的报错
  • 将 router 放到外面后,app 的类型从 Fn 变为 FnOnce
  • HttpServer::new() 只接受 Fn 类型
  • 报错信息指出 closure 只实现了 FnOnce 而不是 Fn
  • router 的移动导致 closure 无法满足 Send 和 Clone 的要求
  • 需要找到解决方案以避免类型不匹配
➡️

继续阅读