whois_rust/
who_is_lookup_options.rs1use std::time::Duration;
2
3use validators::prelude::*;
4
5use crate::{Target, WhoIsError, WhoIsServerValue};
6
7const DEFAULT_FOLLOW: u16 = 2;
8const DEFAULT_TIMEOUT: u64 = 60000;
9
10#[derive(Debug, Clone)]
12pub struct WhoIsLookupOptions {
13 pub target: Target,
15 pub server: Option<WhoIsServerValue>,
17 pub follow: u16,
19 pub timeout: Option<Duration>,
21}
22
23impl WhoIsLookupOptions {
24 #[inline]
25 pub fn from_target(target: Target) -> WhoIsLookupOptions {
26 WhoIsLookupOptions {
27 target,
28 server: None,
29 follow: DEFAULT_FOLLOW,
30 timeout: Some(Duration::from_millis(DEFAULT_TIMEOUT)),
31 }
32 }
33
34 #[allow(clippy::should_implement_trait)]
35 #[inline]
36 pub fn from_str<S: AsRef<str>>(s: S) -> Result<WhoIsLookupOptions, WhoIsError> {
37 Ok(Self::from_target(Target::parse_str(s)?))
38 }
39
40 #[inline]
41 pub fn from_string<S: Into<String>>(s: S) -> Result<WhoIsLookupOptions, WhoIsError> {
42 Ok(Self::from_target(Target::parse_string(s)?))
43 }
44}