From 9cdf4953fe6d09f2ca00113eb2a4df1c73c207e4 Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Tue, 13 Jun 2023 00:53:11 +0100 Subject: simplify domainpart --- src/jid/mod.rs | 51 +++------------------------------------------------ 1 file changed, 3 insertions(+), 48 deletions(-) (limited to 'src') diff --git a/src/jid/mod.rs b/src/jid/mod.rs index c6c157f..f39a1c3 100644 --- a/src/jid/mod.rs +++ b/src/jid/mod.rs @@ -1,53 +1,16 @@ -use std::{ - net::{Ipv4Addr, Ipv6Addr}, - str::FromStr, -}; +use std::str::FromStr; #[derive(PartialEq, Debug)] struct JID { // TODO: validate localpart (length, char] localpart: Option, - domainpart: Domainpart, + domainpart: String, resourcepart: Option, } -#[derive(PartialEq, Debug)] -enum Domainpart { - IPLiteral(Ipv6Addr), - IPv4Address(Ipv4Addr), - // TODO: domain name type, not string - IFQDN(String), -} - -impl FromStr for Domainpart { - type Err = DomainpartParseError; - - fn from_str(s: &str) -> Result { - match s.parse::() { - Ok(ip) => Ok(Domainpart::IPLiteral(ip)), - Err(_) => match s.parse::() { - Ok(ip) => Ok(Domainpart::IPv4Address(ip)), - Err(_) => Ok(Domainpart::IFQDN(s.to_owned())), - }, - } - } -} - -impl TryFrom for Domainpart { - type Error = DomainpartParseError; - - fn try_from(value: String) -> Result { - value.parse() - } -} - -#[derive(Debug)] -enum DomainpartParseError {} - #[derive(Debug)] enum JIDParseError { Empty, - Domainpart(DomainpartParseError), Malformed, } @@ -59,10 +22,6 @@ impl JID { resourcepart, } } - - fn validate(&self) -> bool { - todo!() - } } impl FromStr for JID { @@ -119,11 +78,7 @@ impl std::fmt::Display for JID { f, "{}{}{}", self.localpart.clone().map(|l| l + "@").unwrap_or_default(), - match &self.domainpart { - Domainpart::IPLiteral(addr) => addr.to_string(), - Domainpart::IPv4Address(addr) => addr.to_string(), - Domainpart::IFQDN(domain) => domain.to_owned(), - }, + self.domainpart, self.resourcepart .clone() .map(|r| "/".to_owned() + &r) -- cgit