generic parse_all
jadamcrain opened this issue · 1 comments
jadamcrain commented
https://github.com/aegis4ics/rasn/blob/extension-parsing/rasn/src/parser.rs#L250
I tried to apply this in some other places, but ran into the borrow checker complaining when the return type had a lifetime. Not sure what I need here to get this working, but the goal is to remove all explicit calls to parser.expect_end()
jadamcrain commented
@emgre Figured this out. The magic lifetime incantation was:
pub fn parse_all<'a, T: 'a>(input: &'a[u8], parse: fn(&mut Parser<'a>)-> Result<T, ASNError>) -> Result<T,ASNError> {
let mut parser = Parser::new(input);
let value = parse(&mut parser)?;
parser.expect_end()?;
Ok(value)
}
Namely, both the generic type T and the Parser argument in the parse fn needed the common lifetime annotation.