TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Rust from a Gopher – Lessons 7, 8 and 9

51 点作者 BookPage超过 4 年前

5 条评论

pizza234超过 4 年前
What&#x27;s the rationale for making files modules? Modules being namespaces, and namespaces being collections, it&#x27;s not desirable to have a file being a (large) collection of code.<p>The feature that gives mixed feelings to the author (Re-exporting Imports) is indeed a workaround to this; since each file would externally generate one extra namespacing level, one reexports data structures in order to remove that level.<p>This is odd, as it&#x27;s essentially boilerplate by design. Am I missing something?
评论 #25135203 未加载
评论 #25134979 未加载
评论 #25134814 未加载
评论 #25136297 未加载
kevincox超过 4 年前
I agree the modules are annoying. I realize that the &quot;standard&quot; Rust style is import everything you need. However personally I have long worked with code that avoided imports and found it very helpful to read as it was obvious where each type of function was coming from. However the deeply nested imports makes that painful in a lot of Rust libraries.<p>For example `std::time::Duration`, `std::path::Path`, std::cmp::Ordering`. I wish everything was just directly in `std` such as `std::Duration`, `std::Path` and `std::Ordering`.<p>This re-export that the article talks about is doing this change (which I think is great!) while keeping a nice file structure. I think it is a shame that Rust conflates how you organize your code and how the user of your library sees it by default. However this seems like the best compromise.<p>Example of this pattern in my code: <a href="https:&#x2F;&#x2F;gitlab.com&#x2F;kevincox&#x2F;mario-solver&#x2F;-&#x2F;blob&#x2F;137ac5dea0676d82bb42c8dc0497c84155d69c85&#x2F;src&#x2F;lib.rs#L1-6" rel="nofollow">https:&#x2F;&#x2F;gitlab.com&#x2F;kevincox&#x2F;mario-solver&#x2F;-&#x2F;blob&#x2F;137ac5dea067...</a> (however since this isn&#x27;t a library I use `pub(crate)` instead of `pub`. It works just fine with `pub` except you get a warning if the file doesn&#x27;t have any exports which is a little annoying).
faitswulff超过 4 年前
Every time this post series comes up I have to remember that it&#x27;s mostly a summary of TRPL.
评论 #25137881 未加载
asplake超过 4 年前
“Prelude” is borrowed from Haskell, right?
评论 #25135873 未加载
st1x7超过 4 年前
As a sidenote, does anyone else find the language identification terms cringey? Rustacean, gopher, pythonista... just atrocious.
评论 #25135100 未加载
评论 #25134862 未加载
评论 #25135714 未加载
评论 #25136207 未加载
评论 #25135951 未加载
评论 #25135989 未加载
评论 #25135101 未加载
评论 #25135503 未加载
评论 #25135825 未加载
评论 #25137955 未加载