我想在Rust中为一个闭包声明一个生命周期,但我找不到添加生命周期声明的方法.
use std::str::SplitWhitespace;
pub struct ParserError {
pub message: String,
}
fn missing_token(line_no: usize) -> ParserError {
ParserError {
message: format!("Missing token on line {}", line_no),
}
}
fn process_string(line: &str, line_number: usize) -> Result<(), ParserError> {
let mut tokens = line.split_whitespace();
match try!(tokens.next().ok_or(missing_token(line_number))) {
"hi" => println!("hi"),
_ => println!("Something else"),
}
// The following code gives "cannot infer appropriate lifetime.....
// let nt = |t: &mut SplitWhitespace| t.next().ok_or(missing_token(line_number));
// match try!(nt(&mut tokens)) {
// "there" => println!("there"),
// …Run Code Online (Sandbox Code Playgroud)