diff --git a/jid-rs/Cargo.toml b/jid-rs/Cargo.toml index 9fc6a8a4..c3067946 100644 --- a/jid-rs/Cargo.toml +++ b/jid-rs/Cargo.toml @@ -20,3 +20,4 @@ gitlab = { repository = "xmpp-rs/xmpp-rs" } [dependencies] minidom = { version = "0.12", optional = true } +serde = { version = "1.0", features = ["derive"], optional = true } diff --git a/jid-rs/src/lib.rs b/jid-rs/src/lib.rs index d992e646..b7ce45aa 100644 --- a/jid-rs/src/lib.rs +++ b/jid-rs/src/lib.rs @@ -19,6 +19,9 @@ use std::error::Error as StdError; use std::fmt; use std::str::FromStr; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + /// An error that signifies that a `Jid` cannot be parsed from a string. #[derive(Debug, Clone, PartialEq, Eq)] pub enum JidParseError { @@ -54,6 +57,7 @@ impl fmt::Display for JidParseError { } /// An enum representing a Jabber ID. It can be either a `FullJid` or a `BareJid`. +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum Jid { /// Bare Jid @@ -155,6 +159,7 @@ impl TryFrom for FullJid { /// /// Unlike a `BareJid`, it always contains a resource, and should only be used when you are certain /// there is no case where a resource can be missing. Otherwise, use a `Jid` enum. +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Clone, PartialEq, Eq, Hash)] pub struct FullJid { /// The node part of the Jabber ID, if it exists, else None. @@ -174,6 +179,7 @@ pub struct FullJid { /// /// Unlike a `FullJid`, it can’t contain a resource, and should only be used when you are certain /// there is no case where a resource can be set. Otherwise, use a `Jid` enum. +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Clone, PartialEq, Eq, Hash)] pub struct BareJid { /// The node part of the Jabber ID, if it exists, else None. diff --git a/tokio-xmpp/Cargo.toml b/tokio-xmpp/Cargo.toml index 113614e7..d6a9f39b 100644 --- a/tokio-xmpp/Cargo.toml +++ b/tokio-xmpp/Cargo.toml @@ -25,3 +25,6 @@ trust-dns-resolver = "0.19" trust-dns-proto = "0.19" xml5ever = "0.16" xmpp-parsers = "0.17" + +[features] +serde = ["xmpp-parsers/serde"] diff --git a/xmpp-parsers/Cargo.toml b/xmpp-parsers/Cargo.toml index f3f9a9ae..4c28d4d1 100644 --- a/xmpp-parsers/Cargo.toml +++ b/xmpp-parsers/Cargo.toml @@ -29,6 +29,7 @@ chrono = "0.4.5" component = [] # Disable validation of unknown attributes. disable-validation = [] +serde = ["jid/serde"] [package.metadata.docs.rs] rustdoc-args = [ "--sort-modules-by-appearance", "-Zunstable-options" ] diff --git a/xmpp-rs/Cargo.toml b/xmpp-rs/Cargo.toml index 224d1d99..af6bf03f 100644 --- a/xmpp-rs/Cargo.toml +++ b/xmpp-rs/Cargo.toml @@ -26,3 +26,4 @@ env_logger = "0.7" [features] default = ["avatars"] avatars = [] +serde = ["tokio-xmpp/serde", "xmpp-parsers/serde"]