我正在从https://rust-cli.github.io/book/tutorial/testing.html学习 rust cli 教程,但遇到了编译器警告:
unused `std::result::Result` that must be used
--> src/main.rs:15:13
|
15 | writeln!(writer, "{}", line);
Run Code Online (Sandbox Code Playgroud)
这是完整的代码:
use exitfailure::ExitFailure;
use failure::ResultExt;
use structopt::StructOpt;
#[derive(StructOpt)]
struct Cli {
pattern: String,
#[structopt(parse(from_os_str))]
path: std::path::PathBuf,
}
fn find_matches(content: &str, pattern: &str, mut writer: impl std::io::Write) {
for line in content.lines() {
if line.contains(pattern) {
writeln!(writer, "{}", line);
}
}
}
#[test]
fn find_a_match() {
let mut result = Vec::new();
find_matches("lorem ipsum\ndolor sit amet", "lorem", &mut result);
assert_eq!(result, b"lorem ipsum\n"); …Run Code Online (Sandbox Code Playgroud) rust ×1