Function untwine::parse_pretty

source ·
pub fn parse_pretty<C, T, E>(
    parser: impl for<'a> Fn(&'a ParserContext<'a, C>) -> ParserResult<T, E>,
    input: &str
) -> Result<T, String>
where C: Default, E: Display,
Expand description

Parse a value with a parser function created by the parser! block, and convert the error to a pretty string if there is one.

Examples found in repository?
examples/json.rs (line 65)
60
61
62
63
64
65
66
67
68
69
70
71
72
fn main() {
    print!("> ");
    std::io::stdout().flush().unwrap();
    for line in std::io::stdin().lines() {
        println!();
        match untwine::parse_pretty(json, &line.unwrap().replace("\\n", "\n")) {
            Ok(val) => println!("{val:?}"),
            Err(err) => println!("{err}"),
        }
        print!("\n> ");
        std::io::stdout().flush().unwrap();
    }
}