1 unstable release

0.1.0 Apr 18, 2021

#26 in #const-fn

Download history 1/week @ 2024-03-11 19/week @ 2024-04-01 16/week @ 2024-04-15 70/week @ 2024-06-03 20/week @ 2024-06-10

90 downloads per month

MIT/Apache

8KB
175 lines

const-regex

Proc macro to match regexes in const fns. The regex must be a string literal, but the bytes matched can be any value.

The macro expects an &[u8], but you can easily use str::as_bytes.

const fn this_crate(bytes: &[u8]) -> bool {
    const_regex::match_regex!("^(meta-)*regex matching", bytes)
}

assert!(this_crate(b"meta-meta-regex matching"));
assert!(!this_crate(b"a good idea"));

lib.rs:

Proc macro to match regexes in const fns. The regex must be a string literal, but the bytes matched can be any value.

The macro expects an &[u8], but you can easily use str::as_bytes.

const fn this_crate(bytes: &[u8]) -> bool {
    const_regex::match_regex!("^(meta-)*regex matching", bytes)
}

assert!(this_crate(b"meta-meta-regex matching"));
assert!(!this_crate(b"a good idea"));

Dependencies

~4MB
~62K SLoC