Macro strp::try_scan

source ·
try_scan!() { /* proc-macro */ }
Expand description

Very similar to try_parse, except it allows for 2 or more matched values.

For more details read the documenation of the strp crate.

let source = "10, 20, 30, 40";
let matched = try_scan!(source => "{}, {}, {}, {}");
assert_eq!(matched, Ok((10, 20, 30, 40)));

// Uses stdin as source.
let input: Result<(u32, u32), _> = try_scan!("add {}, {}");
match input {
    Ok((l,r)) => println!("result: {}", l + r),
    Err(e) => println!("parsing error: {e:?}"),
}