From d9aaa3e9ce756dae638718ebd30afda9b00e6555 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 14 May 2018 16:21:39 +0200 Subject: [PATCH] macros: Remove use requirement on error::Error. --- src/attention.rs | 3 +- src/chatstates.rs | 3 +- src/component.rs | 1 - src/delay.rs | 2 +- src/eme.rs | 3 +- src/ibb.rs | 3 +- src/idle.rs | 3 +- src/jingle_ibb.rs | 3 +- src/macros.rs | 66 +++++++++++++++++++++--------------------- src/media_element.rs | 3 +- src/message_correct.rs | 3 +- src/mood.rs | 2 -- src/ping.rs | 3 +- src/receipts.rs | 2 -- src/roster.rs | 2 +- src/sasl.rs | 2 -- src/stanza_id.rs | 3 +- src/stream.rs | 1 - src/websocket.rs | 1 - 19 files changed, 45 insertions(+), 64 deletions(-) diff --git a/src/attention.rs b/src/attention.rs index d7521e9..02cc02f 100644 --- a/src/attention.rs +++ b/src/attention.rs @@ -4,8 +4,6 @@ // 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 error::Error; - use ns; generate_empty_element!(Attention, "attention", ns::ATTENTION); @@ -15,6 +13,7 @@ mod tests { use super::*; use try_from::TryFrom; use minidom::Element; + use error::Error; #[test] fn test_simple() { diff --git a/src/chatstates.rs b/src/chatstates.rs index 33ce0a9..a328e23 100644 --- a/src/chatstates.rs +++ b/src/chatstates.rs @@ -6,8 +6,6 @@ #![deny(missing_docs)] -use error::Error; - use ns; generate_element_enum!( @@ -36,6 +34,7 @@ mod tests { use super::*; use try_from::TryFrom; use minidom::Element; + use error::Error; #[test] fn test_simple() { diff --git a/src/component.rs b/src/component.rs index 778b961..7c74ff1 100644 --- a/src/component.rs +++ b/src/component.rs @@ -4,7 +4,6 @@ // 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 error::Error; use helpers::PlainText; use ns; diff --git a/src/delay.rs b/src/delay.rs index 5591c11..84d12ad 100644 --- a/src/delay.rs +++ b/src/delay.rs @@ -6,7 +6,6 @@ use date::DateTime; -use error::Error; use jid::Jid; use ns; @@ -25,6 +24,7 @@ mod tests { use super::*; use try_from::TryFrom; use minidom::Element; + use error::Error; use std::str::FromStr; #[test] diff --git a/src/eme.rs b/src/eme.rs index b023a5a..de48c3b 100644 --- a/src/eme.rs +++ b/src/eme.rs @@ -4,8 +4,6 @@ // 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 error::Error; - use ns; generate_element_with_only_attributes!( @@ -24,6 +22,7 @@ mod tests { use super::*; use try_from::TryFrom; use minidom::Element; + use error::Error; #[test] fn test_simple() { diff --git a/src/ibb.rs b/src/ibb.rs index 555dfb2..60653da 100644 --- a/src/ibb.rs +++ b/src/ibb.rs @@ -4,8 +4,6 @@ // 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 error::Error; - use ns; use helpers::Base64; @@ -37,6 +35,7 @@ mod tests { use super::*; use try_from::TryFrom; use minidom::Element; + use error::Error; use std::error::Error as StdError; #[test] diff --git a/src/idle.rs b/src/idle.rs index ea82ee3..a94a5ee 100644 --- a/src/idle.rs +++ b/src/idle.rs @@ -6,8 +6,6 @@ use date::DateTime; -use error::Error; - use ns; generate_element_with_only_attributes!(Idle, "idle", ns::IDLE, [ @@ -19,6 +17,7 @@ mod tests { use super::*; use try_from::TryFrom; use minidom::Element; + use error::Error; use std::str::FromStr; use std::error::Error as StdError; diff --git a/src/jingle_ibb.rs b/src/jingle_ibb.rs index 5cc0f25..d96e9b9 100644 --- a/src/jingle_ibb.rs +++ b/src/jingle_ibb.rs @@ -4,8 +4,6 @@ // 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 error::Error; - use ns; use ibb::Stanza; @@ -23,6 +21,7 @@ mod tests { use super::*; use try_from::TryFrom; use minidom::Element; + use error::Error; use std::error::Error as StdError; #[test] diff --git a/src/macros.rs b/src/macros.rs index 752e5bb..54297b3 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -24,7 +24,7 @@ macro_rules! get_attr { ($elem:ident, $attr:tt, required, $value:ident, $func:expr) => ( match $elem.attr($attr) { Some($value) => $func, - None => return Err(Error::ParseError(concat!("Required attribute '", $attr, "' missing."))), + None => return Err(::error::Error::ParseError(concat!("Required attribute '", $attr, "' missing."))), } ); ($elem:ident, $attr:tt, default, $value:ident, $func:expr) => ( @@ -52,11 +52,11 @@ macro_rules! generate_attribute { ),+ } impl ::std::str::FromStr for $elem { - type Err = Error; - fn from_str(s: &str) -> Result<$elem, Error> { + type Err = ::error::Error; + fn from_str(s: &str) -> Result<$elem, ::error::Error> { Ok(match s { $($b => $elem::$a),+, - _ => return Err(Error::ParseError(concat!("Unknown value for '", $name, "' attribute."))), + _ => return Err(::error::Error::ParseError(concat!("Unknown value for '", $name, "' attribute."))), }) } } @@ -78,11 +78,11 @@ macro_rules! generate_attribute { ),+ } impl ::std::str::FromStr for $elem { - type Err = Error; - fn from_str(s: &str) -> Result<$elem, Error> { + type Err = ::error::Error; + fn from_str(s: &str) -> Result<$elem, ::error::Error> { Ok(match s { $($b => $elem::$a),+, - _ => return Err(Error::ParseError(concat!("Unknown value for '", $name, "' attribute."))), + _ => return Err(::error::Error::ParseError(concat!("Unknown value for '", $name, "' attribute."))), }) } } @@ -117,14 +117,14 @@ macro_rules! generate_element_enum { ),+ } impl ::try_from::TryFrom<::minidom::Element> for $elem { - type Err = Error; - fn try_from(elem: ::minidom::Element) -> Result<$elem, Error> { + type Err = ::error::Error; + fn try_from(elem: ::minidom::Element) -> Result<$elem, ::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(Error::ParseError(concat!("This is not a ", $name, " element."))), + _ => return Err(::error::Error::ParseError(concat!("This is not a ", $name, " element."))), }) } } @@ -153,14 +153,14 @@ macro_rules! generate_attribute_enum { ),+ } impl ::try_from::TryFrom<::minidom::Element> for $elem { - type Err = Error; - fn try_from(elem: ::minidom::Element) -> Result<$elem, Error> { + type Err = ::error::Error; + fn try_from(elem: ::minidom::Element) -> Result<$elem, ::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(Error::ParseError(concat!("Invalid ", $name, " ", $attr, " value."))), + _ => return Err(::error::Error::ParseError(concat!("Invalid ", $name, " ", $attr, " value."))), }) } } @@ -183,7 +183,7 @@ macro_rules! check_self { ); ($elem:ident, $name:tt, $ns:expr, $pretty_name:tt) => ( if !$elem.is($name, $ns) { - return Err(Error::ParseError(concat!("This is not a ", $pretty_name, " element."))); + return Err(::error::Error::ParseError(concat!("This is not a ", $pretty_name, " element."))); } ); } @@ -191,7 +191,7 @@ macro_rules! check_self { macro_rules! check_ns_only { ($elem:ident, $name:tt, $ns:expr) => ( if !$elem.has_ns($ns) { - return Err(Error::ParseError(concat!("This is not a ", $name, " element."))); + return Err(::error::Error::ParseError(concat!("This is not a ", $name, " element."))); } ); } @@ -199,7 +199,7 @@ macro_rules! check_ns_only { macro_rules! check_no_children { ($elem:ident, $name:tt) => ( for _ in $elem.children() { - return Err(Error::ParseError(concat!("Unknown child in ", $name, " element."))); + return Err(::error::Error::ParseError(concat!("Unknown child in ", $name, " element."))); } ); } @@ -207,7 +207,7 @@ macro_rules! check_no_children { macro_rules! check_no_attributes { ($elem:ident, $name:tt) => ( for _ in $elem.attrs() { - return Err(Error::ParseError(concat!("Unknown attribute in ", $name, " element."))); + return Err(::error::Error::ParseError(concat!("Unknown attribute in ", $name, " element."))); } ); } @@ -220,7 +220,7 @@ macro_rules! check_no_unknown_attributes { continue; } )* - return Err(Error::ParseError(concat!("Unknown attribute in ", $name, " element."))); + return Err(::error::Error::ParseError(concat!("Unknown attribute in ", $name, " element."))); } ); } @@ -232,9 +232,9 @@ macro_rules! generate_empty_element { pub struct $elem; impl ::try_from::TryFrom<::minidom::Element> for $elem { - type Err = Error; + type Err = ::error::Error; - fn try_from(elem: ::minidom::Element) -> Result<$elem, Error> { + fn try_from(elem: ::minidom::Element) -> Result<$elem, ::error::Error> { check_self!(elem, $name, $ns); check_no_children!(elem, $name); check_no_attributes!(elem, $name); @@ -267,9 +267,9 @@ macro_rules! generate_element_with_only_attributes { } impl ::try_from::TryFrom<::minidom::Element> for $elem { - type Err = Error; + type Err = ::error::Error; - fn try_from(elem: ::minidom::Element) -> Result<$elem, Error> { + fn try_from(elem: ::minidom::Element) -> Result<$elem, ::error::Error> { check_self!(elem, $name, $ns); check_no_children!(elem, $name); check_no_unknown_attributes!(elem, $name, [$($attr_name),*]); @@ -299,8 +299,8 @@ macro_rules! generate_id { #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct $elem(pub String); impl ::std::str::FromStr for $elem { - type Err = Error; - fn from_str(s: &str) -> Result<$elem, Error> { + type Err = ::error::Error; + fn from_str(s: &str) -> Result<$elem, ::error::Error> { // TODO: add a way to parse that differently when needed. Ok($elem(String::from(s))) } @@ -318,15 +318,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 = Error; - fn from_str(s: &str) -> Result<$elem, Error> { + type Err = ::error::Error; + fn from_str(s: &str) -> Result<$elem, ::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 = Error; - fn try_from(elem: ::minidom::Element) -> Result<$elem, Error> { + type Err = ::error::Error; + fn try_from(elem: ::minidom::Element) -> Result<$elem, ::error::Error> { check_self!(elem, $name, $ns); check_no_children!(elem, $name); check_no_attributes!(elem, $name); @@ -361,9 +361,9 @@ macro_rules! generate_element_with_text { } impl ::try_from::TryFrom<::minidom::Element> for $elem { - type Err = Error; + type Err = ::error::Error; - fn try_from(elem: ::minidom::Element) -> Result<$elem, Error> { + fn try_from(elem: ::minidom::Element) -> Result<$elem, ::error::Error> { check_self!(elem, $name, $ns); check_no_children!(elem, $name); check_no_unknown_attributes!(elem, $name, [$($attr_name),*]); @@ -406,9 +406,9 @@ macro_rules! generate_element_with_children { } impl ::try_from::TryFrom<::minidom::Element> for $elem { - type Err = Error; + type Err = ::error::Error; - fn try_from(elem: ::minidom::Element) -> Result<$elem, Error> { + fn try_from(elem: ::minidom::Element) -> Result<$elem, ::error::Error> { check_self!(elem, $name, $ns); check_no_unknown_attributes!(elem, $name, [$($attr_name),*]); let mut parsed_children = vec!(); @@ -420,7 +420,7 @@ macro_rules! generate_element_with_children { continue; } )* - return Err(Error::ParseError(concat!("Unknown child in ", $name, " element."))); + return Err(::error::Error::ParseError(concat!("Unknown child in ", $name, " element."))); } Ok($elem { $( diff --git a/src/media_element.rs b/src/media_element.rs index a3d159a..c9d6a12 100644 --- a/src/media_element.rs +++ b/src/media_element.rs @@ -4,8 +4,6 @@ // 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 error::Error; - use ns; use helpers::TrimmedPlainText; @@ -31,6 +29,7 @@ mod tests { use super::*; use try_from::TryFrom; use minidom::Element; + use error::Error; use data_forms::DataForm; use std::error::Error as StdError; diff --git a/src/message_correct.rs b/src/message_correct.rs index 259eb88..edd9605 100644 --- a/src/message_correct.rs +++ b/src/message_correct.rs @@ -4,8 +4,6 @@ // 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 error::Error; - use ns; generate_element_with_only_attributes!(Replace, "replace", ns::MESSAGE_CORRECT, [ @@ -17,6 +15,7 @@ mod tests { use super::*; use try_from::TryFrom; use minidom::Element; + use error::Error; #[test] fn test_simple() { diff --git a/src/mood.rs b/src/mood.rs index 5ec89f6..ed8b19b 100644 --- a/src/mood.rs +++ b/src/mood.rs @@ -6,8 +6,6 @@ #![deny(missing_docs)] -use error::Error; - use ns; generate_element_enum!( diff --git a/src/ping.rs b/src/ping.rs index cacf3c3..12368c1 100644 --- a/src/ping.rs +++ b/src/ping.rs @@ -5,8 +5,6 @@ // 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 error::Error; - use ns; generate_empty_element!(Ping, "ping", ns::PING); @@ -16,6 +14,7 @@ mod tests { use super::*; use try_from::TryFrom; use minidom::Element; + use error::Error; #[test] fn test_simple() { diff --git a/src/receipts.rs b/src/receipts.rs index 0c785c1..564e8fc 100644 --- a/src/receipts.rs +++ b/src/receipts.rs @@ -4,8 +4,6 @@ // 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 error::Error; - use ns; generate_empty_element!(Request, "request", ns::RECEIPTS); diff --git a/src/roster.rs b/src/roster.rs index 556cf11..01011fd 100644 --- a/src/roster.rs +++ b/src/roster.rs @@ -6,7 +6,6 @@ use jid::Jid; -use error::Error; use ns; generate_elem_id!(Group, "group", ns::ROSTER); @@ -62,6 +61,7 @@ mod tests { use super::*; use try_from::TryFrom; use minidom::Element; + use error::Error; use std::str::FromStr; use compare_elements::NamespaceAwareCompare; diff --git a/src/sasl.rs b/src/sasl.rs index 23a56c4..3cb84c7 100644 --- a/src/sasl.rs +++ b/src/sasl.rs @@ -4,8 +4,6 @@ // 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 error::Error; - use ns; use helpers::Base64; diff --git a/src/stanza_id.rs b/src/stanza_id.rs index a02d8bf..bad8800 100644 --- a/src/stanza_id.rs +++ b/src/stanza_id.rs @@ -6,8 +6,6 @@ use jid::Jid; -use error::Error; - use ns; generate_element_with_only_attributes!(StanzaId, "stanza-id", ns::SID, [ @@ -24,6 +22,7 @@ mod tests { use super::*; use try_from::TryFrom; use minidom::Element; + use error::Error; use std::str::FromStr; #[test] diff --git a/src/stream.rs b/src/stream.rs index ee93411..9d9eff4 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -5,7 +5,6 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. use jid::Jid; -use error::Error; use ns; generate_element_with_only_attributes!(Stream, "stream", ns::STREAM, [ diff --git a/src/websocket.rs b/src/websocket.rs index 4257278..2402164 100644 --- a/src/websocket.rs +++ b/src/websocket.rs @@ -5,7 +5,6 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. use jid::Jid; -use error::Error; use ns; generate_element_with_only_attributes!(Open, "open", ns::WEBSOCKET, [