标签: rust global-variables constants
是否可以定义一个全局常量,其值在运行时开始时计算?像
static START_TIME: time::Timespec = time::get_time();
如果有可能的话。 static和const声明需要编译时间值(calls in constants are limited to struct and enum constructors),不能将其置于函数外(error: expected item, found `let`)。
static
const
calls in constants are limited to struct and enum constructors
error: expected item, found `let`
答案 0 :(得分:2)
我觉得像lazy_static之类的东西可以帮助解决这个问题。