Using a mutable reference breaks clone.

This commit is contained in:
Tom Alexander 2022-10-14 20:25:10 -04:00
parent 112aba3137
commit add717071c
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 4 additions and 4 deletions

View File

@ -2,9 +2,8 @@ use nom::branch::alt;
use nom::error::VerboseError;
use nom::IResult;
#[derive(Clone)]
pub struct NomContext<'a> {
pub fail_matcher: &'a dyn FnMut(&str) -> IResult<&str, &str, VerboseError<&str>>,
pub fail_matcher: &'a mut dyn FnMut(&str) -> IResult<&str, &str, VerboseError<&str>>,
/// You can't have nested bolds or links in org-mode
pub can_match_bold: bool,
pub can_match_link: bool,
@ -12,7 +11,7 @@ pub struct NomContext<'a> {
impl<'a> NomContext<'a> {
pub fn new(
fail_matcher: &'a dyn FnMut(&str) -> IResult<&str, &str, VerboseError<&str>>,
fail_matcher: &'a mut dyn FnMut(&str) -> IResult<&str, &str, VerboseError<&str>>,
) -> Self {
NomContext {
fail_matcher,

View File

@ -133,7 +133,7 @@ pub fn paragraph_end(input: &str) -> Res<&str, &str> {
}
pub fn document(input: &str) -> Res<&str, Vec<(Vec<TextElement>, &str)>> {
let initial_context = NomContext::new(&paragraph_end);
let initial_context = NomContext::new(&mut paragraph_end);
todo!()
// many1(parser_with_context!(paragraph)(initial_context))(input)
}

View File

@ -25,5 +25,6 @@ fn flat_text_element<'s, 'r>(
i: &'s str,
context: &'r mut NomContext,
) -> Res<&'s str, TextElement<'s>> {
not(&mut context.fail_matcher)(i)?;
todo!()
}