Macro sscanf::scanf_get_regex[][src]

scanf_get_regex!() { /* proc-macro */ }

Same as scanf, but returns the Regex without running it. Useful for Debugging or Efficiency.

The Placeholders can be obtained by capturing the Regex and using either Name or index of the Group.

The Name is always type_i where i is the index of the type in the scanf call, starting at 1.

Indices start at 1 as with any Regex, however it is possible that non-std implementations of RegexRepresentation create their own Capture Groups and distort the order, so use with caution. (FullF32 does this for example)

use sscanf::scanf_get_regex;
let input = "Test 5 -2";
let regex = scanf_get_regex!("Test {} {}", usize, i32);
assert_eq!(regex.as_str(), r"^Test (?P<type_1>\+?\d+) (?P<type_2>[-+]?\d{1,10})$");

let output = regex.captures(input);
assert!(output.is_some());
let output = output.unwrap();

let capture_5 = output.name("type_1");
assert!(capture_5.is_some());
assert_eq!(capture_5.unwrap().as_str(), "5");
assert_eq!(capture_5, output.get(1));

let capture_negative_2 = output.name("type_2");
assert!(capture_negative_2.is_some());
assert_eq!(capture_negative_2.unwrap().as_str(), "-2");
assert_eq!(capture_negative_2, output.get(2));