match-domain: Rapid checker for the prefix and suffix matching of domain names, written in Rust
Double-array trie based domain matcher, written in Rust.
This enables you to check if the given domain name matches the prefix or suffix of the domain name in the trie.
Usage
Basic Domain Matching
use DomainMatchingRule;
let domain_matching_rule = try_from
.unwrap;
assert!;
assert!;
assert!;
assert!;
Advanced Matching APIs
The library provides several APIs for more granular matching:
Suffix Matching
use DomainMatchingRule;
let rule = try_from
.unwrap;
// Check if any suffix matches
assert!;
// Get all matching suffixes
let all_matches = rule.find_suffix_match_all;
// Returns reversed strings: ["moc.elgoog", "moc"]
// Get the longest matching suffix
let longest_match = rule.find_suffix_match_longest;
assert_eq!; // "google.com" is longer than "com"
Prefix Matching
use DomainMatchingRule;
let rule = try_from
.unwrap;
// Check if any prefix matches
assert!;
// Get all matching prefixes
let all_matches = rule.find_prefix_match_all;
// Returns: ["www.example", "www"]
// Get the longest matching prefix
let longest_match = rule.find_prefix_match_longest;
assert_eq!; // "www.example" is longer than "www"
Comprehensive Example
use DomainMatchingRule;
let rule = try_from
.unwrap;
// Test different domain matching scenarios
assert!; // Matches suffix pattern
assert!; // Matches prefix pattern
assert!; // Exact match
// Get detailed matching information
let suffix_matches = rule.find_suffix_match_all;
let prefix_matches = rule.find_prefix_match_all;
// Find longest matches for better specificity
let longest_suffix = rule.find_suffix_match_longest;
let longest_prefix = rule.find_prefix_match_longest;
Important Notes
For all matching methods:
- The argument
domain_nameshould be in lowercase - The argument
domain_nameshould not contain a leading dot - Suffix matching returns reversed strings (for internal implementation efficiency)
- Longest match functions return the most specific match when multiple patterns apply