scan_fmt 0.1.0

This crate provides a simple sscanf()-like interface to extract data from strings and stdin.

To use this crate, do:

#[macro_use] extern crate scan_fmt;

Example to read from a string:

# #[macro_use] extern crate scan_fmt;
# fn main() {
  let (a,b,c) = scan_fmt!( "hello 12 345 bye", // input string
                           "hello {} {d} {}",  // format
                           u8, i32, String);   // type of a-c Options
  assert_eq!( a.unwrap(), 12 ) ;
  assert_eq!( b.unwrap(), 345 ) ;
  assert_eq!( c.unwrap(), "bye" ) ;
# }

Special format_string tokens:

Example to read from stdin:

# #[macro_use] extern crate scan_fmt;
# fn main() {
  let (a,b) = scanln_fmt!( "{}-{}",   // format
                           u16, u8);    // type of a&b Options
  match (a,b) {
    (Some(aa),Some(bb)) => println!("Got {} and {}",aa,bb),
    _ => println!("input error")
  }
# }

LIMITATIONS:

There are no compile-time checks to make sure the format strings matches the number of return arguments. Extra return values will be None.

Like sscanf(), whitespace (including \n) is largely ignored.

Conversion to output values is done using parse::().