【问题标题】:Is it possible to execute a custom program at compile time?是否可以在编译时执行自定义程序?
【发布时间】:2014-08-23 09:57:23
【问题描述】:

是否可以在编译时执行自定义程序?

例子:

trait Component..
struct Position..
impl Component for Position..
struct Direction..
impl Component for Direction..

现在我想在编译时计算Componentimpl 的数量。在这种情况下,它将是 2。然后我可以在我的程序中访问这个变量,例如 number_of_components

Rust 或 Rustc 可以实现这样的事情吗?我应该从哪里开始?

【问题讨论】:

    标签: rust


    【解决方案1】:

    Rust 没有 CTFE,所以我不这么认为。

    我认为这样做的唯一方法是通过宏创建 impls/structs,也许吧?但任何不是从宏生成的都不会计入其中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-27
      • 1970-01-01
      • 1970-01-01
      • 2023-04-09
      相关资源
      最近更新 更多