whois_rust/
who_is_lookup_options.rs

1use 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/// The options about how to lookup.
11#[derive(Debug, Clone)]
12pub struct WhoIsLookupOptions {
13    /// The target that you want to lookup.
14    pub target:  Target,
15    /// The WHOIS server that you want to use. If it is **None**, an appropriate WHOIS server will be chosen from the list of WHOIS servers that the `WhoIs` instance have. The default value is **None**.
16    pub server:  Option<WhoIsServerValue>,
17    /// Number of times to follow redirects. The default value is 2.
18    pub follow:  u16,
19    /// Socket timeout in milliseconds. The default value is 60000.
20    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}