【发布时间】:2020-02-11 14:28:00
【问题描述】:
我有这个文件结构
Test
│ .gitignore
│ build.rs
│ Cargo.toml
│
├───.vscode
│ tasks.json
│
├───src
│ main.rs
我有这个 Cargo.toml
[package]
name = "test"
version = "0.1.0"
authors = ["xtricman"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
regex = "*"
我有这个 build.rs
fn main() {
let mt = regex::Regex::new(r"_[1-9][0-9]+.rs|_0.rs\z").unwrap().find("gdf_980.rs");
let mts = if mt.is_some() {
println!("{}", mt.unwrap().as_str());
} else {
println!("None");
};
}
我想在构建脚本中使用 regex crate,但出现编译错误
error[E0433]: failed to resolve: use of undeclared type or module `regex`
--> build.rs:2:14
|
2 | let mt = regex::Regex::new(r"_[1-9][0-9]+.rs|_0.rs\z").unwrap().find("gdf_980.rs");
| ^^^^^ use of undeclared type or module `regex`
Cargo 是否只支持 build.rs 中的 std?
【问题讨论】:
-
如果您使用的是 Rust 2015,那么您还需要将其添加到您的 crate 根目录:
extern crate regex; -
他们没有使用 Rust 2015:
edition = "2018"
标签: rust rust-cargo