我正在嘗試爲我在Rust中編寫的項目編寫文檔。其中一個文檔需要使用regex::Regex
。下面是我想要寫的文檔:不能在Rust文檔測試中使用相關的箱子
/// Return a list of the offsets of the tokens in `s`, as a sequence of `(start, end)`
/// tuples, by splitting the string at each successive match of `regex`.
///
/// # Examples
///
/// ```
/// use rusty_nltk::tokenize::util::regexp_span_tokenize;
/// use regex::Regex;
///
/// let s = "Good muffins cost $3.88\nin New York. Please buy me
/// two of them.\n\nThanks.";
/// let regex = regex::Regex::new(r"\s").unwrap();
/// let spans = regexp_span_tokenize(s, regex).unwrap();
/// ```
它給我這個錯誤:
---- tokenize::util::regexp_span_tokenize_0 stdout ----
<anon>:4:9: 4:14 error: unresolved import `regex::Regex`. Maybe a missing `extern crate regex`? [E0432]
<anon>:4 use regex::Regex;
^~~~~
error: aborting due to previous error
但是當我添加extern crate regex;
,我得到這個錯誤:
---- tokenize::util::regexp_span_tokenize_0 stdout ----
<anon>:3:9: 3:19 error: unresolved import `rusty_nltk::tokenize::util::regexp_span_tokenize`. Maybe a missing `extern crate rusty_nltk`? [E0432]
<anon>:3 use rusty_nltk::tokenize::util::regexp_span_tokenize;
^~~~~~~~~~
<anon>:4:9: 4:14 error: unresolved import `regex::Regex`. Did you mean `self::regex`? [E0432]
<anon>:4 use regex::Regex;
^~~~~
error: aborting due to 2 previous errors
一些相關的部分相關文件是:
src/lib.rs:
extern crate regex;
pub mod tokenize;
的src /記號化/ mod.rs:
extern crate regex;
pub mod util;
(頂)的src /記號化/ util.rs:
extern crate regex;
use regex::Regex;
我在做什麼毛病的佈局我項目?
我剛剛發佈這個答案。我會給出這個答案,並將我的解決方案作爲單獨的答案添加。 – erip