From 40024d2dadba9e70edb2f3448204565ce3f68ab7 Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Sat, 23 Nov 2024 22:39:44 +0000 Subject: switch to using peanuts for xml --- src/jid.rs | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'src/jid.rs') diff --git a/src/jid.rs b/src/jid.rs index 65738dc..233227a 100644 --- a/src/jid.rs +++ b/src/jid.rs @@ -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, } -impl Serialize for JID { - fn serialize(&self, serializer: S) -> Result - 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 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())), } } } -- cgit