diff options
author | cel 🌸 <cel@blos.sm> | 2023-10-20 04:51:56 +0100 |
---|---|---|
committer | cel 🌸 <cel@blos.sm> | 2023-10-20 04:51:56 +0100 |
commit | ba94ee66fafbabd63d6d1ed5edf435d4c46c6796 (patch) | |
tree | fe1bebc35914941b5c4fbd6f0286f4c9f8916154 /src/jid.rs | |
parent | 2536fa4937f0283b4187142cc6cede8e1dbfafa8 (diff) | |
download | luz-ba94ee66fafbabd63d6d1ed5edf435d4c46c6796.tar.gz luz-ba94ee66fafbabd63d6d1ed5edf435d4c46c6796.tar.bz2 luz-ba94ee66fafbabd63d6d1ed5edf435d4c46c6796.zip |
WIP: refactor to parse incoming stream as state machine
Diffstat (limited to '')
-rw-r--r-- | src/jid.rs (renamed from src/jid/mod.rs) | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/jid/mod.rs b/src/jid.rs index e13fed7..65738dc 100644 --- a/src/jid/mod.rs +++ b/src/jid.rs @@ -1,5 +1,7 @@ use std::str::FromStr; +use serde::Serialize; + #[derive(PartialEq, Debug, Clone)] pub struct JID { // TODO: validate localpart (length, char] @@ -8,6 +10,15 @@ 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), @@ -97,6 +108,14 @@ impl TryFrom<String> for JID { } } +impl TryFrom<&str> for JID { + type Error = ParseError; + + fn try_from(value: &str) -> Result<Self, Self::Error> { + value.parse() + } +} + impl std::fmt::Display for JID { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!( |