clouddns_nat_helper/
ipv4source.rs

1//! A way to retrieve an IPv4 address for use in A records.
2//! Each source implements the [`Ipv4Source`] trait.
3//!
4//! The following sources are currently available:
5//! - [`FixedSource`]: Returns a static Ipv4 address
6//! - [`HostnameSource`]: Resolves a hostname to an IPv4 address and returns it
7
8mod fixed;
9mod hostname;
10
11// Export our concrete sources
12pub use fixed::FixedSource;
13pub use hostname::{HostnameSource, HostnameSourceConfig};
14
15use std::{fmt::Display, net::Ipv4Addr};
16
17/// An `Ipv4Source` can be used to retrieve a single IPv4 address for use in DNS records.
18pub trait Ipv4Source {
19    fn addr(&self) -> Result<Ipv4Addr, SourceError>;
20}
21
22#[derive(Debug, Clone, PartialEq, Eq, Hash)]
23pub struct SourceError {
24    msg: String,
25}
26impl Display for SourceError {
27    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
28        write!(f, "{}", self.msg)
29    }
30}
31impl std::error::Error for SourceError {}
32impl From<String> for SourceError {
33    fn from(s: String) -> Self {
34        SourceError { msg: s }
35    }
36}