bird-machine 0.0.1

Compile your regular expressions at compile time.
Documentation
  • Coverage
  • 4.76%
    1 out of 21 items documented1 out of 16 items with examples
  • Size
  • Source code size: 7.92 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 401.06 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 22s Average build duration of successful builds.
  • all releases: 22s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • boringcactus

bird-machine

Compile your regular expressions at compile time.

Almost none of this has actually been implemented yet. Do not use this yet.

Example: find a date

use bird_machine::{bird_machine, Machine};

#[bird_machine(r"^\d{4}-\d{2}-\d{2}$")]
struct Date;

assert!(Date::is_match("2014-01-01"));

Example: iterating over capture groups

use bird_machine::{bird_machine, Machine};

#[bird_machine(r"(\d{4})-(\d{2})-(\d{2})")]
struct Date<'a>(&'a str, &'a str, &'a str);
let input = "2012-03-14, 2013-01-01 and 2014-07-05";
let match_info = Date::captures_iter(input)
    .map(|x: Date| format!("Month: {} Day: {} Year: {}", x.1, x.2, x.0));
let expected = [
    "Month: 03 Day: 14 Year: 2012",
    "Month: 01 Day: 01 Year: 2013",
    "Month: 07 Day: 05 Year: 2014",
];
for (actual, expected) in match_info.zip(expected) {
    assert_eq!(actual, expected);
}

Example: replacement with named capture groups

use bird_machine::{bird_machine, Machine};

#[bird_machine(r"(?P<y>\d{4})-(?P<m>\d{2})-(?P<d>\d{2})")]
struct Date<'a> {
    y: &'a str,
    m: &'a str,
    d: &'a str,
}
let before = "2012-03-14, 2013-01-01 and 2014-07-05";
let after = Date::replace_all(before, "$m/$d/$y");
assert_eq!(after, "03/14/2012, 01/01/2013 and 07/05/2014");

Example: compile-time rejection of invalid regular expressions

use bird_machine::bird_machine;

// this will not compile
#[bird_machine(r"(oops i left this group open")]
struct Bad;