MCPcopy Index your code
hub / github.com/addr-rs/addr

github.com/addr-rs/addr @v0.15.6

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.15.6 ↗ · + Follow
79 symbols 135 edges 11 files 25 documented · 32%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Robust and fast domain name parsing

CI Latest Version Docs

This library uses Mozilla's Public Suffix List to reliably parse domain names in Rust. It will reliably check if a domain has valid syntax. It also checks the length restrictions for each label, total number of labels and full length of domain name.

Examples

use addr::{parse_domain_name, parse_dns_name};

// You can find out the root domain
// or extension of any given domain name
let domain = parse_domain_name("www.example.com")?;
assert_eq!(domain.root(), Some("example.com"));
assert_eq!(domain.suffix(), "com");
assert_eq!(domain.prefix(), Some("www"));

let domain = parse_domain_name("www.食狮.中国")?;
assert_eq!(domain.root(), Some("食狮.中国"));
assert_eq!(domain.suffix(), "中国");

let domain = parse_domain_name("www.xn--85x722f.xn--55qx5d.cn")?;
assert_eq!(domain.root(), Some("xn--85x722f.xn--55qx5d.cn"));
assert_eq!(domain.suffix(), "xn--55qx5d.cn");

let domain = parse_domain_name("a.b.example.uk.com")?;
assert_eq!(domain.root(), Some("example.uk.com"));
assert_eq!(domain.suffix(), "uk.com");

let name = parse_dns_name("_tcp.example.com.")?;
assert_eq!(name.suffix(), Some("com."));

// In any case if the domain's suffix is in the list
// then this is definately a registrable domain name
assert!(domain.has_known_suffix());

TODO

Strict internationalized domain names (IDN) validation (use the idna feature flag)

Use Cases

For those who work with domain names the use cases of this library are plenty. publicsuffix.org/learn lists quite a few. For the sake of brevity, I'm not going to repeat them here. I work for a domain registrar so we make good use of this library. Here are some of the ways this library can be used:

  • Validating domain names. This one is probably obvious. If a domain.has_known_suffix() you can be absolutely sure this is a valid domain name. A regular expression is simply not robust enough.
  • Blacklisting or whitelisting domain names. You can't just blindly do this without knowing the actual registrable domain name otherwise you risk being too restrictive or too lenient. Bad news either way...
  • Extracting the registrable part of a domain name so you can check whether the domain is registered or not.
  • Storing details about a domain name in a DBMS using the registrable part of a domain name as the primary key.

Extension points exported contracts — how you extend this code

DomainName (Interface)
Parses a domain using the list [1 implementers]
src/parser.rs
DnsName (Interface)
Parses any arbitrary string that can be used as a key in a DNS database [1 implementers]
src/parser.rs
EmailAddress (Interface)
Parses an email address using the list [1 implementers]
src/parser.rs

Core symbols most depended-on inside this repo

parse_domain_name
called by 4
src/parser.rs
parse_dns_name
called by 4
src/parser.rs
parse_email_address
called by 4
src/parser.rs
parse_domain_name
called by 4
src/lib.rs
suffix
called by 4
src/dns.rs
error_with
called by 3
src/error.rs
as_str
called by 3
src/dns.rs
parse_dns_name
called by 2
src/lib.rs

Shape

Method 42
Function 20
Class 10
Enum 4
Interface 3

Languages

Rust100%

Modules by API surface

src/matcher.rs12 symbols
src/email.rs12 symbols
src/domain.rs12 symbols
src/dns.rs12 symbols
src/error.rs7 symbols
src/parser.rs6 symbols
tests/integration.rs5 symbols
src/net.rs5 symbols
src/lib.rs5 symbols
src/serde.rs2 symbols
benches/list_benchmark.rs1 symbols

For agents

$ claude mcp add addr \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact