1#![cfg_attr(not(feature = "std"), no_std)]
45#![forbid(unsafe_code)]
46
47pub mod dns;
48pub mod domain;
49pub mod email;
50pub mod error;
51mod matcher;
52#[cfg(feature = "net")]
53pub mod net;
54pub mod parser;
55#[cfg(feature = "serde")]
56mod serde;
57
58#[cfg(not(any(feature = "psl", feature = "publicsuffix")))]
59pub use crate::empty_psl::{parse_dns_name, parse_domain_name, parse_email_address};
60#[cfg(feature = "psl")]
61pub use crate::psl::{parse_dns_name, parse_domain_name, parse_email_address};
62
63#[cfg(feature = "psl")]
65pub mod psl {
66 use crate::parser::{DnsName, DomainName, EmailAddress};
67 use crate::{dns, domain, email, Result};
68
69 pub use psl::List;
70
71 pub fn parse_domain_name(input: &str) -> Result<domain::Name> {
72 List.parse_domain_name(input)
73 }
74
75 pub fn parse_dns_name(input: &str) -> Result<dns::Name> {
76 List.parse_dns_name(input)
77 }
78
79 pub fn parse_email_address(input: &str) -> Result<email::Address> {
80 List.parse_email_address(input)
81 }
82}
83
84#[cfg(not(any(feature = "psl", feature = "publicsuffix")))]
85mod empty_psl {
86 use crate::parser::{DnsName, DomainName, EmailAddress};
87 use crate::{dns, domain, email, Result};
88 use psl_types::Info;
89
90 pub struct List;
91
92 impl psl_types::List for List {
93 fn find<'a, T>(&self, mut labels: T) -> Info
94 where
95 T: Iterator<Item = &'a [u8]>,
96 {
97 match labels.next() {
98 Some(label) => Info {
99 len: label.len(),
100 typ: None,
101 },
102 None => Info { len: 0, typ: None },
103 }
104 }
105 }
106
107 pub fn parse_domain_name(input: &str) -> Result<domain::Name> {
108 List.parse_domain_name(input)
109 }
110
111 pub fn parse_dns_name(input: &str) -> Result<dns::Name> {
112 List.parse_dns_name(input)
113 }
114
115 pub fn parse_email_address(input: &str) -> Result<email::Address> {
116 List.parse_email_address(input)
117 }
118}
119
120#[cfg(feature = "publicsuffix")]
122pub mod publicsuffix {
123 pub use publicsuffix::{IcannList, List, PrivateList};
124}
125
126pub type Result<'a, T> = core::result::Result<T, error::Error<'a>>;