use std::time::Duration;
use validators::prelude::*;
use crate::{Target, WhoIsError, WhoIsServerValue};
const DEFAULT_FOLLOW: u16 = 2;
const DEFAULT_TIMEOUT: Duration = Duration::from_secs(60);
const DEFAULT_MAX_RESPONSE_SIZE: usize = 4 * 1024 * 1024;
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct WhoIsLookupOptions {
pub target: Target,
pub server: Option<WhoIsServerValue>,
pub follow: u16,
pub timeout: Option<Duration>,
pub max_response_size: Option<usize>,
}
impl WhoIsLookupOptions {
#[inline]
pub fn from_target(target: Target) -> WhoIsLookupOptions {
WhoIsLookupOptions {
target,
server: None,
follow: DEFAULT_FOLLOW,
timeout: Some(DEFAULT_TIMEOUT),
max_response_size: Some(DEFAULT_MAX_RESPONSE_SIZE),
}
}
#[allow(clippy::should_implement_trait)]
#[inline]
pub fn from_str<S: AsRef<str>>(s: S) -> Result<WhoIsLookupOptions, WhoIsError> {
Ok(Self::from_target(Target::parse_str(s)?))
}
#[inline]
pub fn from_string<S: Into<String>>(s: S) -> Result<WhoIsLookupOptions, WhoIsError> {
Ok(Self::from_target(Target::parse_string(s)?))
}
}