Skip to content

Latest commit

 

History

History
37 lines (31 loc) · 1.76 KB

README.md

File metadata and controls

37 lines (31 loc) · 1.76 KB

parseln! - a println! counterpart

Test with Code Coverage Check and Lint Codecov

A small helper crate to parse strings using a similar syntax as used in the println! macro.

Installation

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;

Usage

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);

TODO

  • 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.

Disclaimer

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.