Crates.io | strpatmatch |
lib.rs | strpatmatch |
version | 0.1.0 |
source | src |
created_at | 2024-11-29 16:46:32.134475 |
updated_at | 2024-11-29 16:46:32.134475 |
description | Simple string pattern matching |
homepage | |
repository | https://github.com/ManiGhazaee/strpatmatch |
max_upload_size | |
id | 1465800 |
size | 11,183 |
let x = "2a343bb8 c9";
assert_eq!(Some(("2", "343", "8", "9")), match_str!(x, {} "a" {} "bb" {} " c" {}));
assert_eq!(None, match_str!(x, {} "a" {} "d" {})); // x doesn't contain "d"
assert_eq!(Some("a343bb8 c"), match_str!(x, "2" {} "9"));
assert_eq!(None, match_str!(x, "a" {} "c")); // x doesn't start with "a" and end with "c"
let x = match_str!("foo bar baz fuzz", {} "bar" {} "fuzz");
assert_eq!(Some(("foo ", " baz ")), x);
macro expansion:
let x = {
let s = strpatmatch::first_match_start("foo bar baz fuzz", "bar");
if let Some(s) = s {
if let Some(m) = {
if (&"foo bar baz fuzz"[s + "bar".len()..]).ends_with("fuzz") {
Some((
&(&"foo bar baz fuzz"[s
+ "bar"
.len() - "fuzz".len())],
))
} else {
None
}
} {
Some(strpatmatch::tuples::concat((&"foo bar baz fuzz"[0..s],), m))
} else {
None
}
} else {
None
}
};
// assert_eq! ...