summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@blos.sm>2023-06-13 00:53:11 +0100
committerLibravatar cel 🌸 <cel@blos.sm>2023-06-13 00:53:11 +0100
commit9cdf4953fe6d09f2ca00113eb2a4df1c73c207e4 (patch)
tree0b53f8a38fa2a25e91ebeafb3bb7a8397d70f557 /src
parent2b2306b57ca00dddee93f9accb5ac63381d117e7 (diff)
downloadluz-9cdf4953fe6d09f2ca00113eb2a4df1c73c207e4.tar.gz
luz-9cdf4953fe6d09f2ca00113eb2a4df1c73c207e4.tar.bz2
luz-9cdf4953fe6d09f2ca00113eb2a4df1c73c207e4.zip
simplify domainpart
Diffstat (limited to 'src')
-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)