| Crates.io | match-domain |
| lib.rs | match-domain |
| version | 0.1.3 |
| created_at | 2024-11-21 08:55:18.52366+00 |
| updated_at | 2025-09-06 12:53:41.449986+00 |
| description | Rapid checker for the prefix and suffix matching of domain names |
| homepage | https://github.com/junkurihara/rust-match-domain |
| repository | https://github.com/junkurihara/rust-match-domain |
| max_upload_size | |
| id | 1455930 |
| size | 35,501 |
match-domain: Rapid checker for the prefix and suffix matching of domain names, written in RustDouble-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.
use match_domain::DomainMatchingRule;
let domain_matching_rule = DomainMatchingRule::try_from(vec![
"www.google.com".to_string(),
"*.google.com".to_string(),
"yahoo.co.*".to_string(),
])
.unwrap();
assert!(domain_matching_rule.is_matched("wwxx.google.com"));
assert!(domain_matching_rule.is_matched("yahoo.co.jp"));
assert!(!domain_matching_rule.is_matched("www.yahoo.com"));
assert!(!domain_matching_rule.is_matched("www.yahoo.co.jp"));
The library provides several APIs for more granular matching:
use match_domain::DomainMatchingRule;
let rule = DomainMatchingRule::try_from(vec![
"google.com".to_string(),
"*.google.com".to_string(),
"com".to_string(),
])
.unwrap();
// Check if any suffix matches
assert!(rule.find_suffix_match("api.google.com"));
// Get all matching suffixes
let all_matches = rule.find_suffix_match_all("api.google.com");
// Returns reversed strings: ["moc.elgoog", "moc"]
// Get the longest matching suffix
let longest_match = rule.find_suffix_match_longest("api.google.com");
assert_eq!(longest_match, Some("moc.elgoog".to_string())); // "google.com" is longer than "com"
use match_domain::DomainMatchingRule;
let rule = DomainMatchingRule::try_from(vec![
"www.example.*".to_string(),
"www.*".to_string(),
"api.service.*".to_string(),
])
.unwrap();
// Check if any prefix matches
assert!(rule.find_prefix_match("www.example.com"));
// Get all matching prefixes
let all_matches = rule.find_prefix_match_all("www.example.com");
// Returns: ["www.example", "www"]
// Get the longest matching prefix
let longest_match = rule.find_prefix_match_longest("www.example.com");
assert_eq!(longest_match, Some("www.example".to_string())); // "www.example" is longer than "www"
use match_domain::DomainMatchingRule;
let rule = DomainMatchingRule::try_from(vec![
"*.google.com".to_string(), // Suffix pattern
"www.example.*".to_string(), // Prefix pattern
"exact.domain.net".to_string(), // Exact match
])
.unwrap();
// Test different domain matching scenarios
assert!(rule.is_matched("api.google.com")); // Matches suffix pattern
assert!(rule.is_matched("www.example.org")); // Matches prefix pattern
assert!(rule.is_matched("exact.domain.net")); // Exact match
// Get detailed matching information
let suffix_matches = rule.find_suffix_match_all("mail.google.com");
let prefix_matches = rule.find_prefix_match_all("www.example.co.uk");
// Find longest matches for better specificity
let longest_suffix = rule.find_suffix_match_longest("subdomain.google.com");
let longest_prefix = rule.find_prefix_match_longest("www.example.multiple.tlds");
For all matching methods:
domain_name should be in lowercasedomain_name should not contain a leading dot