match-string

Crates.iomatch-string
lib.rsmatch-string
version0.1.2
created_at2025-12-24 13:17:48.305822+00
updated_at2025-12-24 13:31:56.028783+00
descriptionLightweight pattern-matching utilities for strings and sequences, with a proc-macro for ergonomic syntax
homepagehttps://github.com/DexerMatters/match-string
repositoryhttps://github.com/DexerMatters/match-string
max_upload_size
id2003151
size49,779
Dexer Matters (DexerMatters)

documentation

README

match-string

A Rust library for simple and flexible string pattern matching.

Crates.io Documentation License

Examples

Simple matches using built-in tokens:

matches!("Hello, World!"    => ALPHABETIC, ", ", ALPHABETIC);
matches!("123 456"          => NUM, " ", NUM);
matches!("[12,34,56]"     => "[", NUM[","]+, "]");
matches!("foobarfoofoobar"  => ("foo" / "bar")+);

Capturing matched values:

let name: Dest<String> = Dest::new();
let greeting = matches!("Hello, Alice!" => "Hello, ", name@ALPHABETIC, "!");

let arrays: Dest<Vec<usize>> = Dest::new();
let numbers = matches!("[1,2,3]" => "[", (arrays@NUM)[","]+, "]");

Custom tokens:

const VOWELS: Token<char, String> = Token {
    /* Check each character */
    predicate: |ch| "aeiouAEIOU".contains(*ch),
    /* Convert Vec<char> to String */
    parser: |v| v.into_iter().collect(),
    /* Require at least one match */
    at_least: 1,
    /* Skip leading whitespace */
    skip_leading: Some(|ch: &char| ch.is_whitespace()), 
};
Commit count: 0

cargo fmt