From 491264fe008d533299236dfebd17fd705a775165 Mon Sep 17 00:00:00 2001 From: xmppftw Date: Fri, 20 Dec 2024 00:46:04 +0100 Subject: [PATCH] jid: serde support for JID parts --- jid/CHANGELOG.md | 2 ++ jid/src/parts.rs | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/jid/CHANGELOG.md b/jid/CHANGELOG.md index 36b4fa46..2ffe959f 100644 --- a/jid/CHANGELOG.md +++ b/jid/CHANGELOG.md @@ -34,6 +34,8 @@ Version 0.11.1, release 2024-07-23: - Fix clippy lints, cargo doc, and other warnings - xso::FromXmlText and xso::AsXmlText are now implemented for NodePart, DomainPart, and ResourcePart (!485) + - serde::Serialize and serde::Deserialize are now derived for NodePart, + DomainPart, and ResourcePart when serde feature flag is enabled (!499) Version 0.11.0, release 2024-07-23 [YANKED] diff --git a/jid/src/parts.rs b/jid/src/parts.rs index ab9ae98a..35259be4 100644 --- a/jid/src/parts.rs +++ b/jid/src/parts.rs @@ -6,6 +6,8 @@ use core::mem; use core::ops::Deref; use core::str::FromStr; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; use stringprep::{nameprep, nodeprep, resourceprep}; use crate::{BareJid, Error, Jid}; @@ -210,11 +212,13 @@ def_part_types! { /// [`FullJid`][crate::FullJid]. /// /// The corresponding slice type is [`NodeRef`]. + #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct NodePart(String) use nodeprep(err = Error::NodePrep, empty = Error::NodeEmpty, long = Error::NodeTooLong); /// `str`-like type which conforms to the requirements of [`NodePart`]. /// /// See [`NodePart`] for details. + #[cfg_attr(feature = "serde", derive(Serialize))] pub struct ref NodeRef(str); } @@ -222,23 +226,27 @@ def_part_types! { /// The [`DomainPart`] is the part between the (optional) `@` and the /// (optional) `/` in any [`Jid`][crate::Jid], whether /// [`BareJid`][crate::BareJid] or [`FullJid`][crate::FullJid]. + #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct DomainPart(String) use nameprep(err = Error::NamePrep, empty = Error::DomainEmpty, long = Error::DomainTooLong); /// `str`-like type which conforms to the requirements of [`DomainPart`]. /// /// See [`DomainPart`] for details. + #[cfg_attr(feature = "serde", derive(Serialize))] pub struct ref DomainRef(str); } def_part_types! { /// The [`ResourcePart`] is the optional part after the `/` in a /// [`Jid`][crate::Jid]. It is mandatory in [`FullJid`][crate::FullJid]. + #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct ResourcePart(String) use resourceprep(err = Error::ResourcePrep, empty = Error::ResourceEmpty, long = Error::ResourceTooLong); /// `str`-like type which conforms to the requirements of /// [`ResourcePart`]. /// /// See [`ResourcePart`] for details. + #[cfg_attr(feature = "serde", derive(Serialize))] pub struct ref ResourceRef(str); }