diff options
author | 2024-11-23 22:39:44 +0000 | |
---|---|---|
committer | 2024-11-23 22:39:44 +0000 | |
commit | 40024d2dadba9e70edb2f3448204565ce3f68ab7 (patch) | |
tree | 3f08b61debf936c513f300c845d8a1cb29edd7c8 /src/jid.rs | |
parent | 9f2546f6dadd916b0e7fc5be51e92d682ef2487b (diff) | |
download | luz-40024d2dadba9e70edb2f3448204565ce3f68ab7.tar.gz luz-40024d2dadba9e70edb2f3448204565ce3f68ab7.tar.bz2 luz-40024d2dadba9e70edb2f3448204565ce3f68ab7.zip |
switch to using peanuts for xml
Diffstat (limited to 'src/jid.rs')
-rw-r--r-- | src/jid.rs | 28 |
1 files changed, 13 insertions, 15 deletions
@@ -1,7 +1,5 @@ use std::str::FromStr; -use serde::Serialize; - #[derive(PartialEq, Debug, Clone)] pub struct JID { // TODO: validate localpart (length, char] @@ -10,15 +8,6 @@ pub struct JID { pub resourcepart: Option<String>, } -impl Serialize for JID { - fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> - where - S: serde::Serializer, - { - serializer.serialize_str(&self.to_string()) - } -} - pub enum JIDError { NoResourcePart, ParseError(ParseError), @@ -27,7 +16,16 @@ pub enum JIDError { #[derive(Debug)] pub enum ParseError { Empty, - Malformed, + Malformed(String), +} + +impl From<ParseError> for peanuts::Error { + fn from(e: ParseError) -> Self { + match e { + ParseError::Empty => peanuts::Error::DeserializeError("".to_string()), + ParseError::Malformed(e) => peanuts::Error::DeserializeError(e), + } + } } impl JID { @@ -76,7 +74,7 @@ impl FromStr for JID { split[0].to_string(), Some(split[1].to_string()), )), - _ => Err(ParseError::Malformed), + _ => Err(ParseError::Malformed(s.to_string())), } } 2 => { @@ -92,10 +90,10 @@ impl FromStr for JID { split2[0].to_string(), Some(split2[1].to_string()), )), - _ => Err(ParseError::Malformed), + _ => Err(ParseError::Malformed(s.to_string())), } } - _ => Err(ParseError::Malformed), + _ => Err(ParseError::Malformed(s.to_string())), } } } |