netscan_service/
result.rs

1/// Result of a service probe
2#[derive(Clone, Debug, PartialEq)]
3pub struct ServiceProbeResult {
4    pub port: u16,
5    pub service_name: String,
6    pub service_detail: Option<String>,
7    pub response: Vec<u8>,
8    pub error: Option<ServiceProbeError>,
9}
10
11impl ServiceProbeResult {
12    /// Create a new successful probe result
13    pub fn new(port: u16, service_name: String, response: Vec<u8>) -> Self {
14        ServiceProbeResult {
15            port,
16            service_name,
17            service_detail: None,
18            response,
19            error: None,
20        }
21    }
22
23    /// Create a new probe result with an error
24    pub fn with_error(port: u16, service_name: String, error: ServiceProbeError) -> Self {
25        ServiceProbeResult {
26            port,
27            service_name,
28            service_detail: None,
29            response: Vec::new(),
30            error: Some(error),
31        }
32    }
33
34    /// Check if the result contains an error
35    pub fn has_error(&self) -> bool {
36        self.error.is_some()
37    }
38
39    /// Get a reference to the contained error, if any
40    pub fn error(&self) -> Option<&ServiceProbeError> {
41        self.error.as_ref()
42    }
43
44    /// Extract the error, consuming the result
45    pub fn into_error(self) -> Option<ServiceProbeError> {
46        self.error
47    }
48}
49
50#[derive(Clone, Debug, PartialEq)]
51pub enum ServiceProbeError {
52    ConnectionError(String),
53    WriteError(String),
54    ReadError(String),
55    TlsError(String),
56    CustomError(String),
57}