summaryrefslogtreecommitdiffstats
path: root/src/jid
diff options
context:
space:
mode:
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!(