pub struct DomainChecker { /* private fields */ }
Expand description
Main domain checker that coordinates availability checking operations.
The DomainChecker
handles all aspects of domain checking including:
- Protocol selection (RDAP vs WHOIS)
- Concurrent processing
- Error handling and retries
- Result formatting
§Example
use domain_check_lib::{DomainChecker, CheckConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let checker = DomainChecker::new();
let result = checker.check_domain("example.com").await?;
println!("Available: {:?}", result.available);
Ok(())
}
Implementations§
Source§impl DomainChecker
impl DomainChecker
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new domain checker with default configuration.
Default settings:
- Concurrency: 10
- Timeout: 5 seconds
- WHOIS fallback: enabled
- Bootstrap: disabled
- Detailed info: disabled
Sourcepub fn with_config(config: CheckConfig) -> Self
pub fn with_config(config: CheckConfig) -> Self
Create a new domain checker with custom configuration.
§Example
use domain_check_lib::{DomainChecker, CheckConfig};
use std::time::Duration;
let config = CheckConfig::default()
.with_concurrency(20)
.with_timeout(Duration::from_secs(10))
.with_detailed_info(true);
let checker = DomainChecker::with_config(config);
Sourcepub async fn check_domain(
&self,
domain: &str,
) -> Result<DomainResult, DomainCheckError>
pub async fn check_domain( &self, domain: &str, ) -> Result<DomainResult, DomainCheckError>
Check availability of a single domain.
This is the most basic operation - check one domain and return the result. The domain should be a fully qualified domain name (e.g., “example.com”).
The checking process:
- Validates the domain format
- Attempts RDAP check first (modern protocol)
- Falls back to WHOIS if RDAP fails and fallback is enabled
- Returns comprehensive result with timing and method information
§Arguments
domain
- The domain name to check (e.g., “example.com”)
§Returns
A DomainResult
containing availability status and optional details.
§Errors
Returns DomainCheckError
if:
- The domain name is invalid
- Network errors occur
- All checking methods fail
Sourcepub async fn check_domains(
&self,
domains: &[String],
) -> Result<Vec<DomainResult>, DomainCheckError>
pub async fn check_domains( &self, domains: &[String], ) -> Result<Vec<DomainResult>, DomainCheckError>
Check availability of multiple domains concurrently.
This method processes all domains in parallel according to the concurrency setting, then returns all results at once.
§Arguments
domains
- Slice of domain names to check
§Returns
Vector of DomainResult
in the same order as input domains.
§Example
use domain_check_lib::DomainChecker;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let checker = DomainChecker::new();
let domains = vec!["example.com".to_string(), "google.com".to_string(), "test.org".to_string()];
let results = checker.check_domains(&domains).await?;
for result in results {
println!("{}: {:?}", result.domain, result.available);
}
Ok(())
}
Sourcepub fn check_domains_stream(
&self,
domains: &[String],
) -> Pin<Box<dyn Stream<Item = Result<DomainResult, DomainCheckError>> + Send + '_>>
pub fn check_domains_stream( &self, domains: &[String], ) -> Pin<Box<dyn Stream<Item = Result<DomainResult, DomainCheckError>> + Send + '_>>
Check domains and return results as a stream.
This method yields results as they become available, which is useful for real-time updates or when processing large numbers of domains. Results are returned in the order they complete, not input order.
§Arguments
domains
- Slice of domain names to check
§Returns
A stream that yields DomainResult
items as they complete.
§Example
use domain_check_lib::DomainChecker;
use futures::StreamExt;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let checker = DomainChecker::new();
let domains = vec!["example.com".to_string(), "google.com".to_string()];
let mut stream = checker.check_domains_stream(&domains);
while let Some(result) = stream.next().await {
match result {
Ok(domain_result) => println!("✓ {}: {:?}", domain_result.domain, domain_result.available),
Err(e) => println!("✗ Error: {}", e),
}
}
Ok(())
}
Sourcepub async fn check_domains_from_file(
&self,
file_path: &str,
) -> Result<Vec<DomainResult>, DomainCheckError>
pub async fn check_domains_from_file( &self, file_path: &str, ) -> Result<Vec<DomainResult>, DomainCheckError>
Read domain names from a file and check their availability.
The file should contain one domain name per line. Empty lines and lines starting with ‘#’ are ignored as comments.
§Arguments
file_path
- Path to the file containing domain names
§Returns
Vector of DomainResult
for all valid domains in the file.
§Errors
Returns DomainCheckError
if:
- The file cannot be read
- The file contains too many domains (over limit)
- No valid domains are found in the file
Sourcepub fn config(&self) -> &CheckConfig
pub fn config(&self) -> &CheckConfig
Get the current configuration for this checker.
Sourcepub fn set_config(&mut self, config: CheckConfig)
pub fn set_config(&mut self, config: CheckConfig)
Update the configuration for this checker.
This allows modifying settings like concurrency or timeout after the checker has been created. Note that this will recreate the internal protocol clients with the new settings.
Trait Implementations§
Source§impl Clone for DomainChecker
impl Clone for DomainChecker
Source§fn clone(&self) -> DomainChecker
fn clone(&self) -> DomainChecker
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more