mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
macros: Remove use requirement on error::Error.
This commit is contained in:
parent
6f497027f5
commit
d9aaa3e9ce
19 changed files with 45 additions and 64 deletions
|
@ -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() {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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 {
|
||||
$(
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use error::Error;
|
||||
|
||||
use ns;
|
||||
|
||||
generate_element_enum!(
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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, [
|
||||
|
|
|
@ -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, [
|
||||
|
|
Loading…
Reference in a new issue