jid: Add serde support behind feature
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
df47130823
commit
36aaa3e681
5 changed files with 12 additions and 0 deletions
|
@ -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 }
|
||||
|
|
|
@ -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<Jid> 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.
|
||||
|
|
|
@ -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"]
|
||||
|
|
|
@ -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" ]
|
||||
|
|
|
@ -26,3 +26,4 @@ env_logger = "0.7"
|
|||
[features]
|
||||
default = ["avatars"]
|
||||
avatars = []
|
||||
serde = ["tokio-xmpp/serde", "xmpp-parsers/serde"]
|
||||
|
|
Loading…
Reference in a new issue