summaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs66
1 files changed, 2 insertions, 64 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 9417b71..bf1ff82 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,66 +1,4 @@
-use std::{
- convert::Infallible,
- fmt::Display,
- net::{IpAddr, Ipv4Addr, Ipv6Addr},
- str::FromStr,
-};
+pub use error::{Error, Result};
+pub mod error;
pub mod netlink;
-pub mod tmux;
-
-#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
-pub enum Host {
- IpAddr(IpAddr),
- Hostname(String),
-}
-
-impl Host {
- pub fn resolve(&self) -> std::io::Result<Self> {
- match self {
- Self::IpAddr(ip) => dns_lookup::lookup_addr(ip).map(Self::Hostname),
- Self::Hostname(h) => dns_lookup::lookup_host(h)?
- .first()
- .cloned()
- .map(Self::IpAddr)
- .ok_or(std::io::Error::new(
- std::io::ErrorKind::NotFound,
- "resolution not enabled",
- )),
- }
- }
-}
-
-impl FromStr for Host {
- type Err = Infallible;
-
- fn from_str(s: &str) -> Result<Self, Self::Err> {
- Ok(IpAddr::from_str(s).map_or_else(|_| Self::Hostname(s.to_string()), Host::from))
- }
-}
-
-impl From<IpAddr> for Host {
- fn from(value: IpAddr) -> Self {
- Self::IpAddr(value)
- }
-}
-
-impl From<Ipv4Addr> for Host {
- fn from(value: Ipv4Addr) -> Self {
- IpAddr::from(value).into()
- }
-}
-
-impl From<Ipv6Addr> for Host {
- fn from(value: Ipv6Addr) -> Self {
- IpAddr::from(value).into()
- }
-}
-
-impl Display for Host {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- match self {
- Host::IpAddr(i) => write!(f, "{}", i),
- Host::Hostname(s) => write!(f, "{}", s),
- }
- }
-}