rust - How to declare a lifetime for a closure argument -


i declare lifetime closure in rust, can't find way add lifetime declaration.

this closure now:

let nt = |t: &'a mut splitwhitespace| t.next().ok_or(missing_token(line_number)); 

complete sample code on playground.

how can declare lifetime 'a closure?

the &mut splitwhitespace &'b mut splitwhitespace<'a>. relevant lifetime here 'a, specifies how long string slices next returns live. since applied split_whitespace function on line argument, need set 'a same lifetime line argument has.

so first step add lifetime line:

fn process_string<'a>(line: &'a str, line_number: usize) -> result<(), parsererror> { 

and add lifetime type in closure:

let nt = |t: &mut splitwhitespace<'a>| t.next().ok_or(missing_token(line_number)); 

note while answers question, correct solution problem @a.b.'s solution.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -