1use crate::error::ProviderError;
7use crate::types::{IpVersion, Protocol};
8use std::future::Future;
9use std::net::IpAddr;
10use std::pin::Pin;
11
12pub 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 fn get_ip(
41 &self,
42 version: IpVersion,
43 ) -> Pin<Box<dyn Future<Output = Result<IpAddr, ProviderError>> + Send + '_>>;
44}
45
46pub type BoxedProvider = Box<dyn Provider>;
48
49pub(crate) struct DisabledProvider(pub(crate) String);
52
53impl Provider for DisabledProvider {
54 fn name(&self) -> &str {
55 &self.0
56 }
57
58 fn protocol(&self) -> Protocol {
59 Protocol::Http }
61
62 fn get_ip(
63 &self,
64 _version: IpVersion,
65 ) -> Pin<Box<dyn Future<Output = Result<IpAddr, ProviderError>> + Send + '_>> {
66 let name = self.0.clone();
67 Box::pin(async move {
68 Err(ProviderError::message(
69 &name,
70 "provider feature not enabled",
71 ))
72 })
73 }
74}