Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.
  • Look at this:

Code

tuple((opt(tag::<&str, &str, nom::error::Error<&str>>("data-")), is_not(":"), tag(": "), not_line_ending))

This is for when you don't want to have the error automatically float up in a way that requires making the functions return an IResult. This helps where it won't let you use a value because it's owned by a function that would make it disappear when the function is finished.

Code

use nom::bytes::complete::tag;
use nom::error::Error;

#[derive(Debug)]
struct Widget {
    text: String,
}

fn main() {
    let mut w = Widget {
        text: "the quick brown fox".to_string(),
    };
    parse(&mut w);
    dbg!(w);
}

fn parse(w: &mut Widget) {
    let response = tag::<&str, &str, Error<&str>>("the quick ")(w.text.as_str()).unwrap();
    w.text = response.0.to_string();
}

Working with nom without the `?`` method