1use crate::error::ProviderError;
7use crate::types::{IpVersion, Protocol};
8use async_trait::async_trait;
9use std::net::IpAddr;
10
11#[async_trait]
13pub trait Provider: Send + Sync {
14 fn name(&self) -> &str;
16
17 fn protocol(&self) -> Protocol;
19
20 fn supports_v4(&self) -> bool {
22 true
23 }
24
25 fn supports_v6(&self) -> bool {
27 false
28 }
29
30 fn supports_version(&self, version: IpVersion) -> bool {
32 match version {
33 IpVersion::V4 => self.supports_v4(),
34 IpVersion::V6 => self.supports_v6(),
35 IpVersion::Any => self.supports_v4() || self.supports_v6(),
36 }
37 }
38
39 async fn get_ip(&self, version: IpVersion) -> Result<IpAddr, ProviderError>;
41}
42
43pub type BoxedProvider = Box<dyn Provider>;
45
46pub(crate) struct DisabledProvider(pub(crate) String);
49
50#[async_trait]
51impl Provider for DisabledProvider {
52 fn name(&self) -> &str {
53 &self.0
54 }
55
56 fn protocol(&self) -> Protocol {
57 Protocol::Http }
59
60 async fn get_ip(&self, _version: IpVersion) -> Result<IpAddr, ProviderError> {
61 Err(ProviderError::message(
62 &self.0,
63 "provider feature not enabled",
64 ))
65 }
66}