From 409a1dafa9c8165b533cc66d4a2b0d1bd5a6bb1f Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sun, 13 Jan 2019 12:39:51 +0100 Subject: [PATCH] Move Error, helpers and macros into a util module. --- src/attention.rs | 2 +- src/bind.rs | 2 +- src/blocking.rs | 2 +- src/bookmarks.rs | 2 +- src/caps.rs | 2 +- src/chatstates.rs | 2 +- src/component.rs | 2 +- src/data_forms.rs | 2 +- src/date.rs | 2 +- src/delay.rs | 4 +- src/disco.rs | 4 +- src/ecaps2.rs | 2 +- src/eme.rs | 2 +- src/forwarding.rs | 2 +- src/hashes.rs | 4 +- src/ibb.rs | 4 +- src/ibr.rs | 4 +- src/idle.rs | 2 +- src/iq.rs | 4 +- src/jingle.rs | 2 +- src/jingle_ft.rs | 2 +- src/jingle_ibb.rs | 2 +- src/jingle_message.rs | 2 +- src/jingle_s5b.rs | 4 +- src/lib.rs | 11 +---- src/mam.rs | 2 +- src/media_element.rs | 4 +- src/message.rs | 4 +- src/message_correct.rs | 2 +- src/muc/muc.rs | 4 +- src/muc/user.rs | 4 +- src/nick.rs | 2 +- src/ping.rs | 2 +- src/presence.rs | 4 +- src/pubsub/event.rs | 4 +- src/pubsub/pubsub.rs | 4 +- src/roster.rs | 4 +- src/rsm.rs | 4 +- src/sasl.rs | 4 +- src/stanza_error.rs | 2 +- src/stanza_id.rs | 2 +- src/{ => util}/compare_elements.rs | 0 src/{ => util}/error.rs | 0 src/{ => util}/helpers.rs | 2 +- src/{ => util}/macros.rs | 76 +++++++++++++++--------------- src/version.rs | 2 +- 46 files changed, 98 insertions(+), 107 deletions(-) rename src/{ => util}/compare_elements.rs (100%) rename src/{ => util}/error.rs (100%) rename src/{ => util}/helpers.rs (97%) rename src/{ => util}/macros.rs (87%) diff --git a/src/attention.rs b/src/attention.rs index bd4c7a15e431cc8f5548cd837b96f97abbc59968..1910c8c13bf75657512b3db9b07c6e549bed0f89 100644 --- a/src/attention.rs +++ b/src/attention.rs @@ -19,7 +19,7 @@ impl MessagePayload for Attention {} mod tests { use super::*; #[cfg(not(feature = "disable-validation"))] - use crate::error::Error; + use crate::util::error::Error; use minidom::Element; use try_from::TryFrom; diff --git a/src/bind.rs b/src/bind.rs index 9d3a894f8950c2aee20cda960de6b17acc6a4bac..8ded3e6ac10c8bb01e61ba9bb0d3c56b1f1d4d24 100644 --- a/src/bind.rs +++ b/src/bind.rs @@ -4,7 +4,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -use crate::error::Error; +use crate::util::error::Error; use crate::iq::{IqResultPayload, IqSetPayload}; use crate::ns; use jid::Jid; diff --git a/src/blocking.rs b/src/blocking.rs index 53417f7f749ccebc425fceeee2da39d63b03f337..2b021185995c8427f28bcf1c921a780a60f57076 100644 --- a/src/blocking.rs +++ b/src/blocking.rs @@ -4,7 +4,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -use crate::error::Error; +use crate::util::error::Error; use crate::iq::{IqGetPayload, IqResultPayload, IqSetPayload}; use crate::ns; use jid::Jid; diff --git a/src/bookmarks.rs b/src/bookmarks.rs index 6048b2f074023e7df09ef2103777d42fcdd6e0c9..12f95707fc8f7c7bfbcc61d938be68aae9aa7b2e 100644 --- a/src/bookmarks.rs +++ b/src/bookmarks.rs @@ -72,7 +72,7 @@ impl Storage { #[cfg(test)] mod tests { use super::*; - use crate::compare_elements::NamespaceAwareCompare; + use crate::util::compare_elements::NamespaceAwareCompare; use minidom::Element; use try_from::TryFrom; diff --git a/src/caps.rs b/src/caps.rs index 74042be31a368be7a0d5b756a7393ec0ad77a09c..73c79378ffa1a613c406977599e150303db59f35 100644 --- a/src/caps.rs +++ b/src/caps.rs @@ -6,7 +6,7 @@ use crate::data_forms::DataForm; use crate::disco::{DiscoInfoQuery, DiscoInfoResult, Feature, Identity}; -use crate::error::Error; +use crate::util::error::Error; use crate::hashes::{Algo, Hash}; use crate::ns; use crate::presence::PresencePayload; diff --git a/src/chatstates.rs b/src/chatstates.rs index 4eb173f11b796d1ef554f7f766638de486efef6f..2bf2d1b1fe0cbd91cc4803101bb941d03add554a 100644 --- a/src/chatstates.rs +++ b/src/chatstates.rs @@ -32,7 +32,7 @@ impl MessagePayload for ChatState {} #[cfg(test)] mod tests { use super::*; - use crate::error::Error; + use crate::util::error::Error; use crate::ns; use minidom::Element; use try_from::TryFrom; diff --git a/src/component.rs b/src/component.rs index cb42fd7a319e9b2223e93b8ff6fb2b104ced3af4..722495b8a02b6aea322c16a990070586e299ea4b 100644 --- a/src/component.rs +++ b/src/component.rs @@ -4,7 +4,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -use crate::helpers::PlainText; +use crate::util::helpers::PlainText; use digest::Digest; use sha1::Sha1; diff --git a/src/data_forms.rs b/src/data_forms.rs index 9d7608dfc3cceb0fa504a77375568f9cda421542..30dbd29aa478ac2c9dd918bb3de0e7c08f4196c7 100644 --- a/src/data_forms.rs +++ b/src/data_forms.rs @@ -4,7 +4,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -use crate::error::Error; +use crate::util::error::Error; use crate::media_element::MediaElement; use crate::ns; use minidom::Element; diff --git a/src/date.rs b/src/date.rs index a6a99e0743ac9f78753091555fb48026eba97004..1d3389b0651623ffc7ec802a64e9de6106032b1a 100644 --- a/src/date.rs +++ b/src/date.rs @@ -4,7 +4,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -use crate::error::Error; +use crate::util::error::Error; use chrono::{DateTime as ChronoDateTime, FixedOffset}; use minidom::{ElementEmitter, IntoAttributeValue, IntoElements}; use std::str::FromStr; diff --git a/src/delay.rs b/src/delay.rs index 4defc94ace00bfb8f219af40d953e62ef3a12a8d..a02b44b1a4338929806b75529c2af166cb945191 100644 --- a/src/delay.rs +++ b/src/delay.rs @@ -5,7 +5,7 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. use crate::date::DateTime; -use crate::helpers::PlainText; +use crate::util::helpers::PlainText; use crate::message::MessagePayload; use crate::presence::PresencePayload; use jid::Jid; @@ -32,7 +32,7 @@ impl PresencePayload for Delay {} #[cfg(test)] mod tests { use super::*; - use crate::error::Error; + use crate::util::error::Error; use minidom::Element; use std::str::FromStr; use try_from::TryFrom; diff --git a/src/disco.rs b/src/disco.rs index 79d89b26d0dfe345bc691ab7e89df4e60b1aeb7c..d61cf361dc3b3258bc238aa11f391fe22dfb282c 100644 --- a/src/disco.rs +++ b/src/disco.rs @@ -5,7 +5,7 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. use crate::data_forms::{DataForm, DataFormType}; -use crate::error::Error; +use crate::util::error::Error; use crate::iq::{IqGetPayload, IqResultPayload}; use crate::ns; use jid::Jid; @@ -236,7 +236,7 @@ impl IqResultPayload for DiscoItemsResult {} #[cfg(test)] mod tests { use super::*; - use crate::compare_elements::NamespaceAwareCompare; + use crate::util::compare_elements::NamespaceAwareCompare; use std::str::FromStr; #[cfg(target_pointer_width = "32")] diff --git a/src/ecaps2.rs b/src/ecaps2.rs index 2fc011b806408af9f4ef5300ebc67f6ab338970b..846fa6da0d75e1720e4bdff06a9a3e33cd3ffad6 100644 --- a/src/ecaps2.rs +++ b/src/ecaps2.rs @@ -156,7 +156,7 @@ pub fn query_ecaps2(hash: Hash) -> DiscoInfoQuery { #[cfg(test)] mod tests { use super::*; - use crate::error::Error; + use crate::util::error::Error; use minidom::Element; use try_from::TryFrom; diff --git a/src/eme.rs b/src/eme.rs index 4b8ffbe6bcb2a6ee0e990b9a8b73ad9094e05e2a..cd24e43d03b7bf95799d75b86b086d3b280d8ab1 100644 --- a/src/eme.rs +++ b/src/eme.rs @@ -24,7 +24,7 @@ impl MessagePayload for ExplicitMessageEncryption {} #[cfg(test)] mod tests { use super::*; - use crate::error::Error; + use crate::util::error::Error; use minidom::Element; use try_from::TryFrom; diff --git a/src/forwarding.rs b/src/forwarding.rs index e36ebf8eed09979f79e984e5a2d0ffe937e01f6b..5dfa4aea0413a754808f3ddbbf4f1601ac85c76e 100644 --- a/src/forwarding.rs +++ b/src/forwarding.rs @@ -26,7 +26,7 @@ generate_element!( #[cfg(test)] mod tests { use super::*; - use crate::error::Error; + use crate::util::error::Error; use minidom::Element; use try_from::TryFrom; diff --git a/src/hashes.rs b/src/hashes.rs index a7773ee1cda05bc2b509270586cb361cbd59cd38..041b81fc4795415b230bda7d2393a40a11e16cab 100644 --- a/src/hashes.rs +++ b/src/hashes.rs @@ -4,8 +4,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -use crate::error::Error; -use crate::helpers::Base64; +use crate::util::error::Error; +use crate::util::helpers::Base64; use base64; use minidom::IntoAttributeValue; use std::str::FromStr; diff --git a/src/ibb.rs b/src/ibb.rs index f2aff83efe950cbd8475382dc054464d09393330..960761187becc66ba7d9e1f7dd2ec02922d635ba 100644 --- a/src/ibb.rs +++ b/src/ibb.rs @@ -4,7 +4,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -use crate::helpers::Base64; +use crate::util::helpers::Base64; use crate::iq::IqSetPayload; generate_id!( @@ -72,7 +72,7 @@ impl IqSetPayload for Close {} #[cfg(test)] mod tests { use super::*; - use crate::error::Error; + use crate::util::error::Error; use minidom::Element; use std::error::Error as StdError; use try_from::TryFrom; diff --git a/src/ibr.rs b/src/ibr.rs index 39aa229d68dbfabcc353a2fdd7f9c64d1b587758..f19c47c131ba137644addac47d35d03ee884ee63 100644 --- a/src/ibr.rs +++ b/src/ibr.rs @@ -5,7 +5,7 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. use crate::data_forms::DataForm; -use crate::error::Error; +use crate::util::error::Error; use crate::iq::{IqGetPayload, IqResultPayload, IqSetPayload}; use crate::ns; use minidom::Element; @@ -118,7 +118,7 @@ impl From for Element { #[cfg(test)] mod tests { use super::*; - use crate::compare_elements::NamespaceAwareCompare; + use crate::util::compare_elements::NamespaceAwareCompare; #[cfg(target_pointer_width = "32")] #[test] diff --git a/src/idle.rs b/src/idle.rs index df2d005d67b6a6361b3e02f51d961ee534f528a5..bbf3f15114546636f20c49de18edec939d15ce8e 100644 --- a/src/idle.rs +++ b/src/idle.rs @@ -21,7 +21,7 @@ impl PresencePayload for Idle {} #[cfg(test)] mod tests { use super::*; - use crate::error::Error; + use crate::util::error::Error; use minidom::Element; use std::error::Error as StdError; use std::str::FromStr; diff --git a/src/iq.rs b/src/iq.rs index d4ee8b4197fc5d696017fdabff473adc0e21798b..b155b97c928a7da5072e561d6d6d78888085adac 100644 --- a/src/iq.rs +++ b/src/iq.rs @@ -5,7 +5,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -use crate::error::Error; +use crate::util::error::Error; use crate::ns; use crate::stanza_error::StanzaError; use jid::Jid; @@ -218,7 +218,7 @@ impl From for Element { #[cfg(test)] mod tests { use super::*; - use crate::compare_elements::NamespaceAwareCompare; + use crate::util::compare_elements::NamespaceAwareCompare; use crate::disco::DiscoInfoQuery; use crate::stanza_error::{DefinedCondition, ErrorType}; diff --git a/src/jingle.rs b/src/jingle.rs index 2a3c09669e2eb1ec0a73901024ee99a2afd12a81..63c78a0f808ec9b678502ca1a19ddcc2e44ba2a8 100644 --- a/src/jingle.rs +++ b/src/jingle.rs @@ -4,7 +4,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -use crate::error::Error; +use crate::util::error::Error; use crate::iq::IqSetPayload; use crate::ns; use jid::Jid; diff --git a/src/jingle_ft.rs b/src/jingle_ft.rs index 32dd41f6aeb7233bc5a236796ea7bfa6fa80418f..fce18cdf47ff7d8eda6b0eb153b88364ab2249fb 100644 --- a/src/jingle_ft.rs +++ b/src/jingle_ft.rs @@ -5,7 +5,7 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. use crate::date::DateTime; -use crate::error::Error; +use crate::util::error::Error; use crate::hashes::Hash; use crate::jingle::{ContentId, Creator}; use crate::ns; diff --git a/src/jingle_ibb.rs b/src/jingle_ibb.rs index 1addc1ee4f9c5d41a87494cab0f3af5e9df17ced..08370e1f7f9dd328abb9dd3c2194547c20422111 100644 --- a/src/jingle_ibb.rs +++ b/src/jingle_ibb.rs @@ -24,7 +24,7 @@ attributes: [ #[cfg(test)] mod tests { use super::*; - use crate::error::Error; + use crate::util::error::Error; use minidom::Element; use std::error::Error as StdError; use try_from::TryFrom; diff --git a/src/jingle_message.rs b/src/jingle_message.rs index 02c1e9924fb3e3449fce3c132ca26e7ee509aa7d..1a520223bcfadfa680e3526435d2c7db0b40724d 100644 --- a/src/jingle_message.rs +++ b/src/jingle_message.rs @@ -4,7 +4,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -use crate::error::Error; +use crate::util::error::Error; use crate::jingle::SessionId; use crate::ns; use minidom::Element; diff --git a/src/jingle_s5b.rs b/src/jingle_s5b.rs index e85390caa2b89b1b62a3cd2dcbbd226feac00db0..58c4a27dd36a705bb5a6bd159459a1700655116f 100644 --- a/src/jingle_s5b.rs +++ b/src/jingle_s5b.rs @@ -4,7 +4,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -use crate::error::Error; +use crate::util::error::Error; use crate::ns; use jid::Jid; use minidom::Element; @@ -275,7 +275,7 @@ impl From for Element { #[cfg(test)] mod tests { use super::*; - use crate::compare_elements::NamespaceAwareCompare; + use crate::util::compare_elements::NamespaceAwareCompare; use std::str::FromStr; #[cfg(target_pointer_width = "32")] diff --git a/src/lib.rs b/src/lib.rs index 36eb788250d34834804e416b93a55a1c839e45fc..ed16e05ecf552375532a5de139310a621ace2f39 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,20 +26,11 @@ pub use minidom::Element; -/// Error type returned by every parser on failure. -pub mod error; /// XML namespace definitions used through XMPP. pub mod ns; -/// Various helpers. -mod helpers; -/// Helper macros to parse and serialise more easily. #[macro_use] -mod macros; - -#[cfg(test)] -/// Namespace-aware comparison for tests -mod compare_elements; +mod util; /// RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core pub mod bind; diff --git a/src/mam.rs b/src/mam.rs index 8124be9feb760ef3132e9bf78b5d4bc81f45571f..453b4f606deeafbf321d58867e27564969f7e94f 100644 --- a/src/mam.rs +++ b/src/mam.rs @@ -5,7 +5,7 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. use crate::data_forms::DataForm; -use crate::error::Error; +use crate::util::error::Error; use crate::forwarding::Forwarded; use crate::iq::{IqGetPayload, IqResultPayload, IqSetPayload}; use crate::message::MessagePayload; diff --git a/src/media_element.rs b/src/media_element.rs index f3a623870c06c53da518519365e23857d804e378..639b71cea3401fcf764ffba7a54e36c760328900 100644 --- a/src/media_element.rs +++ b/src/media_element.rs @@ -4,7 +4,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -use crate::helpers::TrimmedPlainText; +use crate::util::helpers::TrimmedPlainText; generate_element!( /// Represents an URI used in a media element. @@ -46,7 +46,7 @@ generate_element!( mod tests { use super::*; use crate::data_forms::DataForm; - use crate::error::Error; + use crate::util::error::Error; use minidom::Element; use std::error::Error as StdError; use try_from::TryFrom; diff --git a/src/message.rs b/src/message.rs index 159bcd2d8fe76492cb2a92236e24226ddf837239..fe32300e5d353a33aefda76822c6fbd66f436dfe 100644 --- a/src/message.rs +++ b/src/message.rs @@ -4,7 +4,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -use crate::error::Error; +use crate::util::error::Error; use crate::ns; use jid::Jid; use minidom::Element; @@ -254,7 +254,7 @@ impl From for Element { #[cfg(test)] mod tests { use super::*; - use crate::compare_elements::NamespaceAwareCompare; + use crate::util::compare_elements::NamespaceAwareCompare; use std::str::FromStr; #[cfg(target_pointer_width = "32")] diff --git a/src/message_correct.rs b/src/message_correct.rs index 3bba10e7a187abf3cb1fcdb2e116a9b014fda2f8..05663c8daa34cb40755378242a03e74b1c37d586 100644 --- a/src/message_correct.rs +++ b/src/message_correct.rs @@ -21,7 +21,7 @@ impl MessagePayload for Replace {} #[cfg(test)] mod tests { use super::*; - use crate::error::Error; + use crate::util::error::Error; use minidom::Element; use try_from::TryFrom; diff --git a/src/muc/muc.rs b/src/muc/muc.rs index fc596fa9c95adfe4f759cefead11bbabca89974e..9d29cc963c924481d79855c4e7791aebfa4e63b3 100644 --- a/src/muc/muc.rs +++ b/src/muc/muc.rs @@ -102,8 +102,8 @@ impl Muc { #[cfg(test)] mod tests { use super::*; - use crate::compare_elements::NamespaceAwareCompare; - use crate::error::Error; + use crate::util::compare_elements::NamespaceAwareCompare; + use crate::util::error::Error; use minidom::Element; use std::str::FromStr; use try_from::TryFrom; diff --git a/src/muc/user.rs b/src/muc/user.rs index 56c111e8ef18b7cd8a6be65a3544bdff4bb17efb..46a893337ea7b8525c35c67850dcc31382a45487 100644 --- a/src/muc/user.rs +++ b/src/muc/user.rs @@ -5,7 +5,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -use crate::error::Error; +use crate::util::error::Error; use crate::ns; use jid::Jid; use minidom::Element; @@ -238,7 +238,7 @@ generate_element!( #[cfg(test)] mod tests { use super::*; - use crate::compare_elements::NamespaceAwareCompare; + use crate::util::compare_elements::NamespaceAwareCompare; use std::error::Error as StdError; #[test] diff --git a/src/nick.rs b/src/nick.rs index 03f544aaa9455e9d9b8894972098676b9f898df2..1fbeb1026752abc44799299b2b271f1fa3f450f2 100644 --- a/src/nick.rs +++ b/src/nick.rs @@ -15,7 +15,7 @@ generate_elem_id!( mod tests { use super::*; #[cfg(not(feature = "disable-validation"))] - use crate::error::Error; + use crate::util::error::Error; use minidom::Element; use try_from::TryFrom; diff --git a/src/ping.rs b/src/ping.rs index 018531205c3d16f9b6b681251fe12091b1e091ab..62bd0b1a2e6c215f644864d43c277833ca84787a 100644 --- a/src/ping.rs +++ b/src/ping.rs @@ -21,7 +21,7 @@ impl IqGetPayload for Ping {} mod tests { use super::*; #[cfg(not(feature = "disable-validation"))] - use crate::error::Error; + use crate::util::error::Error; use minidom::Element; use try_from::TryFrom; diff --git a/src/presence.rs b/src/presence.rs index 7e3e8aa8f78a6afb68bfd7430467580f96a7e527..4a464f9c3ced4dfb767f71f38404ef203479fb09 100644 --- a/src/presence.rs +++ b/src/presence.rs @@ -5,7 +5,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -use crate::error::Error; +use crate::util::error::Error; use crate::ns; use jid::Jid; use minidom::{Element, ElementEmitter, IntoAttributeValue, IntoElements}; @@ -354,7 +354,7 @@ impl From for Element { #[cfg(test)] mod tests { use super::*; - use crate::compare_elements::NamespaceAwareCompare; + use crate::util::compare_elements::NamespaceAwareCompare; #[cfg(target_pointer_width = "32")] #[test] diff --git a/src/pubsub/event.rs b/src/pubsub/event.rs index 0cef2c397c453bf00b9bddb5e08d43158a2a9e60..4e8b9311b167292fb9e11a6b1c00ba22223bac1b 100644 --- a/src/pubsub/event.rs +++ b/src/pubsub/event.rs @@ -6,7 +6,7 @@ use crate::data_forms::DataForm; use crate::date::DateTime; -use crate::error::Error; +use crate::util::error::Error; use crate::ns; use crate::pubsub::{ItemId, NodeName, Subscription, SubscriptionId}; use jid::Jid; @@ -298,7 +298,7 @@ impl From for Element { #[cfg(test)] mod tests { use super::*; - use crate::compare_elements::NamespaceAwareCompare; + use crate::util::compare_elements::NamespaceAwareCompare; use std::str::FromStr; #[test] diff --git a/src/pubsub/pubsub.rs b/src/pubsub/pubsub.rs index e406d867a0eb126ea0c4c901e2c48ef53fc883b3..637b050aea1d04716d867789effcec21d862f9ea 100644 --- a/src/pubsub/pubsub.rs +++ b/src/pubsub/pubsub.rs @@ -5,7 +5,7 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. use crate::data_forms::DataForm; -use crate::error::Error; +use crate::util::error::Error; use crate::iq::{IqGetPayload, IqResultPayload, IqSetPayload}; use crate::ns; use crate::pubsub::{ItemId, NodeName, Subscription, SubscriptionId}; @@ -540,7 +540,7 @@ impl From for Element { #[cfg(test)] mod tests { use super::*; - use crate::compare_elements::NamespaceAwareCompare; + use crate::util::compare_elements::NamespaceAwareCompare; #[test] fn create() { diff --git a/src/roster.rs b/src/roster.rs index b40d2d5dd3741e0d77e1b8d8216ccf813fe6bc64..29086aec2ae7777b00ffebebcf072a4e2587c458 100644 --- a/src/roster.rs +++ b/src/roster.rs @@ -92,8 +92,8 @@ impl IqResultPayload for Roster {} #[cfg(test)] mod tests { use super::*; - use crate::compare_elements::NamespaceAwareCompare; - use crate::error::Error; + use crate::util::compare_elements::NamespaceAwareCompare; + use crate::util::error::Error; use minidom::Element; use std::str::FromStr; use try_from::TryFrom; diff --git a/src/rsm.rs b/src/rsm.rs index 0cd048ec854d5c4bb11c16906093356c0498aaff..1dd5f47f71ccfd4c0d93971379a1385b1b6a6aa6 100644 --- a/src/rsm.rs +++ b/src/rsm.rs @@ -4,7 +4,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -use crate::error::Error; +use crate::util::error::Error; use crate::ns; use minidom::Element; use try_from::TryFrom; @@ -180,7 +180,7 @@ impl From for Element { #[cfg(test)] mod tests { use super::*; - use crate::compare_elements::NamespaceAwareCompare; + use crate::util::compare_elements::NamespaceAwareCompare; #[cfg(target_pointer_width = "32")] #[test] diff --git a/src/sasl.rs b/src/sasl.rs index db9b17e6fd3a90f071898c15cad65054fdd0dde3..fecdbfa6b6ca7017593af6d3df9bd7839daa1e9d 100644 --- a/src/sasl.rs +++ b/src/sasl.rs @@ -4,8 +4,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -use crate::error::Error; -use crate::helpers::Base64; +use crate::util::error::Error; +use crate::util::helpers::Base64; use crate::ns; use minidom::Element; use std::collections::BTreeMap; diff --git a/src/stanza_error.rs b/src/stanza_error.rs index c5e62026848b668e5d269d0fdeb8c4f1e3a7eeef..7a4d421aad5505ce9f02a93c2169a4180ba6bd1b 100644 --- a/src/stanza_error.rs +++ b/src/stanza_error.rs @@ -4,7 +4,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -use crate::error::Error; +use crate::util::error::Error; use crate::message::MessagePayload; use crate::ns; use crate::presence::PresencePayload; diff --git a/src/stanza_id.rs b/src/stanza_id.rs index 2bac2de3e1d7be592ebc053bf1a84d30edb6187a..c9cefad724a1c8583bfdc908a56d777068ab915b 100644 --- a/src/stanza_id.rs +++ b/src/stanza_id.rs @@ -37,7 +37,7 @@ impl MessagePayload for OriginId {} #[cfg(test)] mod tests { use super::*; - use crate::error::Error; + use crate::util::error::Error; use minidom::Element; use std::str::FromStr; use try_from::TryFrom; diff --git a/src/compare_elements.rs b/src/util/compare_elements.rs similarity index 100% rename from src/compare_elements.rs rename to src/util/compare_elements.rs diff --git a/src/error.rs b/src/util/error.rs similarity index 100% rename from src/error.rs rename to src/util/error.rs diff --git a/src/helpers.rs b/src/util/helpers.rs similarity index 97% rename from src/helpers.rs rename to src/util/helpers.rs index e4d2324475a6eb3d13bb27eab7db787c4638d49e..fad0b671cc4670153339cfc31e2a3e503c375938 100644 --- a/src/helpers.rs +++ b/src/util/helpers.rs @@ -4,7 +4,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -use crate::error::Error; +use crate::util::error::Error; use base64; /// Codec for plain text content. diff --git a/src/macros.rs b/src/util/macros.rs similarity index 87% rename from src/macros.rs rename to src/util/macros.rs index d0dfbc0603df5dfd2e67abff8e7a10ef32ef1b00..fd3a0ada1febe68c177c15e1a4e57dc7cf4968db 100644 --- a/src/macros.rs +++ b/src/util/macros.rs @@ -25,7 +25,7 @@ macro_rules! get_attr { match $elem.attr($attr) { Some($value) => $func, None => { - return Err(crate::error::Error::ParseError(concat!( + return Err(crate::util::error::Error::ParseError(concat!( "Required attribute '", $attr, "' missing." @@ -58,11 +58,11 @@ macro_rules! generate_attribute { ),+ } impl ::std::str::FromStr for $elem { - type Err = crate::error::Error; - fn from_str(s: &str) -> Result<$elem, crate::error::Error> { + type Err = crate::util::error::Error; + fn from_str(s: &str) -> Result<$elem, crate::util::error::Error> { Ok(match s { $($b => $elem::$a),+, - _ => return Err(crate::error::Error::ParseError(concat!("Unknown value for '", $name, "' attribute."))), + _ => return Err(crate::util::error::Error::ParseError(concat!("Unknown value for '", $name, "' attribute."))), }) } } @@ -84,11 +84,11 @@ macro_rules! generate_attribute { ),+ } impl ::std::str::FromStr for $elem { - type Err = crate::error::Error; - fn from_str(s: &str) -> Result<$elem, crate::error::Error> { + type Err = crate::util::error::Error; + fn from_str(s: &str) -> Result<$elem, crate::util::error::Error> { Ok(match s { $($b => $elem::$a),+, - _ => return Err(crate::error::Error::ParseError(concat!("Unknown value for '", $name, "' attribute."))), + _ => return Err(crate::util::error::Error::ParseError(concat!("Unknown value for '", $name, "' attribute."))), }) } } @@ -117,11 +117,11 @@ macro_rules! generate_attribute { None, } impl ::std::str::FromStr for $elem { - type Err = crate::error::Error; - fn from_str(s: &str) -> Result { + type Err = crate::util::error::Error; + fn from_str(s: &str) -> Result { Ok(match s { $value => $elem::$symbol, - _ => return Err(crate::error::Error::ParseError(concat!("Unknown value for '", $name, "' attribute."))), + _ => return Err(crate::util::error::Error::ParseError(concat!("Unknown value for '", $name, "' attribute."))), }) } } @@ -149,12 +149,12 @@ macro_rules! generate_attribute { False, } impl ::std::str::FromStr for $elem { - type Err = crate::error::Error; - fn from_str(s: &str) -> Result { + type Err = crate::util::error::Error; + fn from_str(s: &str) -> Result { Ok(match s { "true" | "1" => $elem::True, "false" | "0" => $elem::False, - _ => return Err(crate::error::Error::ParseError(concat!("Unknown value for '", $name, "' attribute."))), + _ => return Err(crate::util::error::Error::ParseError(concat!("Unknown value for '", $name, "' attribute."))), }) } } @@ -188,14 +188,14 @@ macro_rules! generate_element_enum { ),+ } impl ::try_from::TryFrom<::minidom::Element> for $elem { - type Err = crate::error::Error; - fn try_from(elem: ::minidom::Element) -> Result<$elem, crate::error::Error> { + type Err = crate::util::error::Error; + fn try_from(elem: ::minidom::Element) -> Result<$elem, crate::util::error::Error> { check_ns_only!(elem, $name, $ns); check_no_children!(elem, $name); check_no_attributes!(elem, $name); Ok(match elem.name() { $($enum_name => $elem::$enum,)+ - _ => return Err(crate::error::Error::ParseError(concat!("This is not a ", $name, " element."))), + _ => return Err(crate::util::error::Error::ParseError(concat!("This is not a ", $name, " element."))), }) } } @@ -227,14 +227,14 @@ macro_rules! generate_attribute_enum { ),+ } impl ::try_from::TryFrom<::minidom::Element> for $elem { - type Err = crate::error::Error; - fn try_from(elem: ::minidom::Element) -> Result<$elem, crate::error::Error> { + type Err = crate::util::error::Error; + fn try_from(elem: ::minidom::Element) -> Result<$elem, crate::util::error::Error> { check_ns_only!(elem, $name, $ns); check_no_children!(elem, $name); check_no_unknown_attributes!(elem, $name, [$attr]); Ok(match get_attr!(elem, $attr, required) { $($enum_name => $elem::$enum,)+ - _ => return Err(crate::error::Error::ParseError(concat!("Invalid ", $name, " ", $attr, " value."))), + _ => return Err(crate::util::error::Error::ParseError(concat!("Invalid ", $name, " ", $attr, " value."))), }) } } @@ -257,7 +257,7 @@ macro_rules! check_self { }; ($elem:ident, $name:tt, $ns:ident, $pretty_name:tt) => { if !$elem.is($name, crate::ns::$ns) { - return Err(crate::error::Error::ParseError(concat!( + return Err(crate::util::error::Error::ParseError(concat!( "This is not a ", $pretty_name, " element." @@ -269,7 +269,7 @@ macro_rules! check_self { macro_rules! check_ns_only { ($elem:ident, $name:tt, $ns:ident) => { if !$elem.has_ns(crate::ns::$ns) { - return Err(crate::error::Error::ParseError(concat!( + return Err(crate::util::error::Error::ParseError(concat!( "This is not a ", $name, " element." @@ -282,7 +282,7 @@ macro_rules! check_no_children { ($elem:ident, $name:tt) => { #[cfg(not(feature = "disable-validation"))] for _ in $elem.children() { - return Err(crate::error::Error::ParseError(concat!( + return Err(crate::util::error::Error::ParseError(concat!( "Unknown child in ", $name, " element." @@ -295,7 +295,7 @@ macro_rules! check_no_attributes { ($elem:ident, $name:tt) => { #[cfg(not(feature = "disable-validation"))] for _ in $elem.attrs() { - return Err(crate::error::Error::ParseError(concat!( + return Err(crate::util::error::Error::ParseError(concat!( "Unknown attribute in ", $name, " element." @@ -313,7 +313,7 @@ macro_rules! check_no_unknown_attributes { continue; } )* - return Err(crate::error::Error::ParseError(concat!("Unknown attribute in ", $name, " element."))); + return Err(crate::util::error::Error::ParseError(concat!("Unknown attribute in ", $name, " element."))); } ); } @@ -325,9 +325,9 @@ macro_rules! generate_empty_element { pub struct $elem; impl ::try_from::TryFrom<::minidom::Element> for $elem { - type Err = crate::error::Error; + type Err = crate::util::error::Error; - fn try_from(elem: ::minidom::Element) -> Result<$elem, crate::error::Error> { + fn try_from(elem: ::minidom::Element) -> Result<$elem, crate::util::error::Error> { check_self!(elem, $name, $ns); check_no_children!(elem, $name); check_no_attributes!(elem, $name); @@ -351,8 +351,8 @@ macro_rules! generate_id { #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct $elem(pub String); impl ::std::str::FromStr for $elem { - type Err = crate::error::Error; - fn from_str(s: &str) -> Result<$elem, crate::error::Error> { + type Err = crate::util::error::Error; + fn from_str(s: &str) -> Result<$elem, crate::util::error::Error> { // TODO: add a way to parse that differently when needed. Ok($elem(String::from(s))) } @@ -371,15 +371,15 @@ macro_rules! generate_elem_id { #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct $elem(pub String); impl ::std::str::FromStr for $elem { - type Err = crate::error::Error; - fn from_str(s: &str) -> Result<$elem, crate::error::Error> { + type Err = crate::util::error::Error; + fn from_str(s: &str) -> Result<$elem, crate::util::error::Error> { // TODO: add a way to parse that differently when needed. Ok($elem(String::from(s))) } } impl ::try_from::TryFrom<::minidom::Element> for $elem { - type Err = crate::error::Error; - fn try_from(elem: ::minidom::Element) -> Result<$elem, crate::error::Error> { + type Err = crate::util::error::Error; + fn try_from(elem: ::minidom::Element) -> Result<$elem, crate::util::error::Error> { check_self!(elem, $name, $ns); check_no_children!(elem, $name); check_no_attributes!(elem, $name); @@ -440,7 +440,7 @@ macro_rules! do_parse_elem { }; ($temp:ident: Option = $constructor:ident => $elem:ident, $name:tt, $parent_name:tt) => { if $temp.is_some() { - return Err(crate::error::Error::ParseError(concat!( + return Err(crate::util::error::Error::ParseError(concat!( "Element ", $parent_name, " must not have more than one ", @@ -452,7 +452,7 @@ macro_rules! do_parse_elem { }; ($temp:ident: Required = $constructor:ident => $elem:ident, $name:tt, $parent_name:tt) => { if $temp.is_some() { - return Err(crate::error::Error::ParseError(concat!( + return Err(crate::util::error::Error::ParseError(concat!( "Element ", $parent_name, " must not have more than one ", @@ -472,7 +472,7 @@ macro_rules! finish_parse_elem { $temp }; ($temp:ident: Required = $name:tt, $parent_name:tt) => { - $temp.ok_or(crate::error::Error::ParseError(concat!( + $temp.ok_or(crate::util::error::Error::ParseError(concat!( "Missing child ", $name, " in ", @@ -540,9 +540,9 @@ macro_rules! generate_element { } impl ::try_from::TryFrom<::minidom::Element> for $elem { - type Err = crate::error::Error; + type Err = crate::util::error::Error; - fn try_from(elem: ::minidom::Element) -> Result<$elem, crate::error::Error> { + fn try_from(elem: ::minidom::Element) -> Result<$elem, crate::util::error::Error> { check_self!(elem, $name, $ns); check_no_unknown_attributes!(elem, $name, [$($attr_name),*]); $( @@ -555,7 +555,7 @@ macro_rules! generate_element { continue; } )* - return Err(crate::error::Error::ParseError(concat!("Unknown child in ", $name, " element."))); + return Err(crate::util::error::Error::ParseError(concat!("Unknown child in ", $name, " element."))); } Ok($elem { $( diff --git a/src/version.rs b/src/version.rs index c9e08c32199060179e7be0ab3b3229c3ce9a51d0..5aa4d2fbb2acbfe5e3d3d2e8207e57d43958a195 100644 --- a/src/version.rs +++ b/src/version.rs @@ -41,7 +41,7 @@ impl IqResultPayload for VersionResult {} #[cfg(test)] mod tests { use super::*; - use crate::compare_elements::NamespaceAwareCompare; + use crate::util::compare_elements::NamespaceAwareCompare; use minidom::Element; use try_from::TryFrom;