summaryrefslogtreecommitdiffstats
path: root/src/jid
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/jid/mod.rs51
1 files changed, 3 insertions, 48 deletions
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<String>,
- domainpart: Domainpart,
+ domainpart: String,
resourcepart: Option<String>,
}
-#[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<Self, Self::Err> {
- match s.parse::<Ipv6Addr>() {
- Ok(ip) => Ok(Domainpart::IPLiteral(ip)),
- Err(_) => match s.parse::<Ipv4Addr>() {
- Ok(ip) => Ok(Domainpart::IPv4Address(ip)),
- Err(_) => Ok(Domainpart::IFQDN(s.to_owned())),
- },
- }
- }
-}
-
-impl TryFrom<String> for Domainpart {
- type Error = DomainpartParseError;
-
- fn try_from(value: String) -> Result<Self, Self::Error> {
- 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)