use std::time::Duration;
use validators::prelude::*;
use crate::{Target, WhoIsError, WhoIsServerValue};
const DEFAULT_FOLLOW: u16 = 2;
const DEFAULT_TIMEOUT: u64 = 60000;
#[derive(Debug, Clone)]
pub struct WhoIsLookupOptions {
pub target: Target,
pub server: Option<WhoIsServerValue>,
pub follow: u16,
pub timeout: Option<Duration>,
}
impl WhoIsLookupOptions {
#[inline]
pub fn from_target(target: Target) -> WhoIsLookupOptions {
WhoIsLookupOptions {
target,
server: None,
follow: DEFAULT_FOLLOW,
timeout: Some(Duration::from_millis(DEFAULT_TIMEOUT)),
}
}
#[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)?))
}
}