- Here is my code:
use combine_language::LanguageEnv;
use combine::stream::easy;
use core::fmt;
use std::fmt::Formatter;
use std::error::Error;
use combine::Parser;
use combine::choice;
use combine::parser::combinator::no_partial;
use combine::parser::char::string;
pub struct Foo<'a> {
data: Vec<MyParser<'a, String>>,
}
impl <'a> Foo<'a> {
pub fn new() -> Foo<'a> {
let data = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16"
.split_whitespace()
.map(|s: & str| {
let t =
no_partial(string(s)).map(|s: & str| s.to_string());
Box::new(t ) as MyParser<'a, String> } )
.collect::<Vec<_>>();
Foo { data }
}
pub fn make_parser(&mut self) -> impl Parser<Input=easy::Stream<&'a str>, Output=String, PartialState=()> {
let t = choice(self.data.as_mut_slice());
return no_partial(t);
// return Box::new(no_partial(t));
}
}
pub type MyParser<'a, T> = Box<Parser<Input=easy::Stream<&'a str>, Output=T, PartialState=()> + 'a>;
#[test]
fn empty () {
}
- Here is the error:
|
30 | let t = choice(self.data.as_mut_slice());
| ^^^^^^^^^^^^
|
note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the method body at 29:5...
|
29 | / pub fn make_parser(&mut self) -> impl Parser<Input=easy::Stream<&'a str>, Output=String, PartialState=()> {
30 | | let t = choice(self.data.as_mut_slice());
31 | | return no_partial(t);
32 | | // return Box::new(no_partial(t));
33 | | }
| |_____^
note: ...so that reference does not outlive borrowed content
|
30 | let t = choice(self.data.as_mut_slice());
| ^^^^^^^^^
note: but, the lifetime must be valid for the lifetime 'a as defined on the impl at 16:7...
What am I doing wrong here? The .as_mut_slice is on the data field of the struct, so it should live atleast 'a
.