知识卡片

普通读书笔记卡 · 10504.c.4.d · 生成模型:未记录

闭包为每个线程建应用

理解等级:中级

闭包是可调用的值。例中传给 HttpServer::new 的 || { ... } 无参数,并以尾表达式返回注册好路由的 App。框架可由多个工作线程调用工厂,各自得到应用值。这个模式把创建过程交给框架,调用点只描述怎样配置应用。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)》第01章《A Tour of Rust》|用类型连接表单、处理器和响应,来源项目 `book-source`,`extracted/Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)/_epub-src/OEBPS/ch01.xhtml#serving-pages-to-the-web` - 结论依据:原文说明工作线程各调用闭包创建 App。 - 原始内容:Each thread calls our closure to get a fresh copy of the App value that tells it how to route and handle requests.