Macros for more involved pattern matching than the standard library allows.
Find a file
2025-11-05 16:15:40 -06:00
src enable implicit type conversions for capture groups 2025-11-05 16:15:40 -06:00
tests enable implicit type conversions for capture groups 2025-11-05 16:15:40 -06:00
.gitignore enable implicit type conversions for capture groups 2025-11-05 16:15:40 -06:00
Cargo.lock initial commit 2025-11-05 14:50:36 -06:00
Cargo.toml initial commit 2025-11-05 14:50:36 -06:00
CHANGELOG.md initial commit 2025-11-05 14:50:36 -06:00
LICENSE initial commit 2025-11-05 14:50:36 -06:00
README.md enable implicit type conversions for capture groups 2025-11-05 16:15:40 -06:00

match-utils

Macros for more involved pattern matching than the standard library allows.

Examples

You can create a matcher for multiple regex patterns using the regex_match! macro. It can handle pure matching, as well as using a fixed number of unnamed capture groups. For example:

let a = "some string to match";

regex_match! (a, {
    "^some" => println!("Starts with some!"),
    "add *(-?[0-9]+), *(-?[0-9]+)" [lhs: i32, rhs: i32] => {
        println!("Sum: {}", lval + rval);
    },
    _ => println!("Default case")
});

Type arguments can be provided, assuming that they implement the FromStr trait.

License

This library is licensed under The Apache License, version 2.0.

Copyright 2025 Dustin Thomas io@cptlobster.dev

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.