A small helper crate to parse strings using a similar syntax as used in the println!
macro.
To use this library in a project simply add
[dependencies]
parseline = { git = "https://github.com/albheim/parseline" }
to your project Cargo.toml
and then import parseline as
use parseline::parseln;
It can be used either with already defined variables as
let month: String;
let day: isize;
parseln!("Date: apr 13", "Date: {} {}", month, day);
or by generating new binding, though then we need to supply the type to be parsed
parseln!("Date: apr 13", "Date: {} {}", month: String, day: i32);
- Currently it is not possible to mix these methods.
- Allow for writing to references, automatically dereference?
- cargo doc?
- Don't do split->collect->iter, check macro book for tips on how to do indexing in repeating macros.
This is the first crate I have made and it was mostly as a learning experience. I needed some parsing for Advent of Code and thought regular expressions were overkill, and figuring out how to set up a crate with tests and how to create the needed macro was a good learning experience.