prse 0.1.0

A tiny string parsing utility.
Documentation

Prse

Prse is a small string parsing library with an emphasis on speed and ease of use. (It's also no-std compatible!)

It provides the parse! macro which allows you to easily parse strings into any type using a format args like syntax.

Examples

use prse::parse;

let input = "5 + -2 = 3";

let mut total = 0_i32;
let (lhs, rhs): (i32, i32) = parse!(input, "{} + {} = {total}");

assert_eq!(lhs + rhs, total);

It also allows you to parse into multiple variables separated by a separator in a single go.

use prse::parse;

let input = "My farm contains some amount of booleans: true || false || true || false";
let mut many: Vec<bool> = vec![];

// the variable to store the answer in is many and the separator is equal to " || "
parse!(input, "My farm contains some amount of booleans: {many: || :}");

assert_eq!(many, vec![true, false, true, false]);

Additionally you can use the try_parse! macro if you don't want to panic when the parsing fails.

use prse::try_parse;
use std::path::PathBuf;

let input = "cd C:\\windows\\system32";
let path: Result<PathBuf, _> = try_parse!(input, "cd {}");

assert_eq!(path.unwrap(), PathBuf::from("C:\\windows\\system32"));

Roadmap

  • Write some ui tests
  • Benchmarking
  • Have the ability to specify multiple parses if the first one fails

License