← 返回起始笔记位置

知识卡片

普通读书笔记卡 · 10346.a.3.d · 生成模型:未记录

从调用端设计接口

理解等级:中级

先写使用者期望的代码,例如 ThreadPool::new(4) 后用 pool.execute 提交任务。再用 cargo check 逐步处理缺类型、缺构造函数、缺方法等诊断,建立模块与签名。当空实现也能通过编译时,应以行为验证确认任务真的被调用。方法签名可先定下来,内部实现可以继续迭代。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《The Rust Programming Language(第2版)》第20章 最终项目:构建多线程 Web 服务器(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c20.xhtml`,块 0128) - 结论依据:原文说明先写希望调用的 API,再按外部形状设计实现,后续空 execute 的例子说明编译的覆盖边界。 - 原始内容:Before we begin implementing a thread pool, let’s talk about what using the pool should look like. When you’re trying to design code, writing the client interface first can help guide your design. Write the API of the code so it’s structured in the way you want to call it; then implement the functionality within that structure rather than implementing the functionality and then designing the public API.