cze*_*rny 4 constants global-variables rust
是否可以定义一个全局常量,其值在运行时开始计算?就像是
static START_TIME: time::Timespec = time::get_time();
Run Code Online (Sandbox Code Playgroud)
如果可能的话。staticandconst声明需要编译时值 ( calls in constants are limited to struct and enum constructors) 并且 let 不能放在函数 ( error: expected item, found `let`)之外。
我认为像lazy_static这样的东西可以帮助解决这个问题。
| 归档时间: |
|
| 查看次数: |
1757 次 |
| 最近记录: |