【发布时间】:2021-04-25 18:06:18
【问题描述】:
我收到以下编译错误:
static optionsRegex: regex::Regex
= match regex::Regex::new(r###"$(~?[\w-]+(?:=[^,]*)?(?:,~?[\w-]+(?:=[^,]*)?)*)$"###) {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ statics cannot evaluate destructors
Ok(r) => r,
Default => panic!("Invalid optionsRegex")
};
更多细节:我需要在创建时访问一个已编译的正则表达式供 struct 使用。任何 Rust 文档链接或解释表示赞赏。
附:我想我知道 Rust 需要知道何时销毁它,但我不知道如何制作它,除了避免使其成为静态并在创建结构时每次需要它时传递一些带有所有正则表达式的结构。
【问题讨论】:
标签: rust static destructor