scanfmt 0.2.1

Scanfmt: easy to use macro for parsing a string
Documentation
  • Coverage
  • 21.74%
    5 out of 23 items documented0 out of 17 items with examples
  • Size
  • Source code size: 11.8 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.72 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • fee1-dead/scanfmt
    2 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • fee1-dead

Scanfmt

This crate offers a macro for parsing text.

The macro accepts a format string, and the name of arguments to parse into.

The syntax of the format string literal is quite similar to the format! macro family:

format_string := text [ maybe_format text ] *
maybe_format := '{' '{' | '}' '}' | format
format := '{' [ argument ] [ ':' format_spec ] '}'
argument := integer | identifier

format_spec := 'o' | 'x' | 'X' | 'b'

In the above grammar, text must not contain any '{' or '}' characters.

Usage

use scanfmt::{scanfmt, ScanError};
fn my_format(s: &str) -> Result<(u16, u32), ScanError> {
    let a;
    let b;
    scanfmt!(s, "a: {}, b: {}", a, b);
    Ok((a, b))
}

Note that scanfmt! requires the function to return a result to ensure that variables are always initialized.