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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Deriving Traits in Rust with Procedural Macros

65 点作者 naftulikay超过 6 年前

5 条评论

cbrewster超过 6 年前
Great article, there aren&#x27;t many resources for writing proc macros right now.<p>However, I think this could be done with a generic impl of WritableTemplate for all T where T: Template.
评论 #18816414 未加载
评论 #18816374 未加载
评论 #18814794 未加载
reissbaker超过 6 年前
I&#x27;m a Rust fan and procedural macros are legitimately a cool feature, but the example seems much more simply solved via inheritance. You could do this without procedural macros by using a default method definition on the WritableTemplate trait, since WritableTemplate inherits from Template and should have the render method in scope.<p>This could just be a slightly contrived example to show the neat kinds of things you can do with procedural macros, though. If you needed a reference to the original struct definition, for example, procedural macros allow you to do the kinds of transformations at compile time that other languages need runtime reflection for.
rhn_mk1超过 6 年前
I&#x27;m a little confused about the statement that procedural macros are new in the 2018 edition.<p>I&#x27;ve always stuck to what Fedora was shiping, and they seem to be shipping the stable versions. Yet I used procedural macros back in 2016 already [0]. Does my memory fail me, or is there some other change that happened now?<p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;rhn&#x2F;gpx-rust&#x2F;blob&#x2F;master&#x2F;gpx_debug&#x2F;src&#x2F;lib.rs" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;rhn&#x2F;gpx-rust&#x2F;blob&#x2F;master&#x2F;gpx_debug&#x2F;src&#x2F;li...</a>
insertcredit超过 6 年前
Rust is morphing into a complexity beast that rivals C++. When the cognitive load require to read and write Rust code far exceeds that required of other, more popular languages, the future does not look rosy.
评论 #18814211 未加载
评论 #18812532 未加载
评论 #18812490 未加载
sierdolij超过 6 年前
Lifetimes - implicit&#x2F;explicit semantics for how long a name is considered alive, whereas in C++ there would be a delete or falling out of scope.<p>Borrowing - I still don&#x27;t understand how or why a non-reference is implicitly consumed by passing it (read-only intention) by value(?) to another function and then can&#x27;t be used again. Pony does explicit consumption.<p>There seems to be a need for training classes in Rust that explain the development philosophy, because it&#x27;s not readily apparent from the online resources to anecdotal me who&#x27;s able to code in Haskell, Elxir, Erlang, Clojure, C, C++17, Ruby, Python, Go, assembly and LLVM IR.
评论 #18814136 未加载
评论 #18812495 未加载
评论 #18812787 未加载
评论 #18814242 未加载
评论 #18812836 未加载