Use TryFrom from the try_from crate, instead of the unstable feature.

This makes xmpp-parsers usable on stable.
This commit is contained in:
Emmanuel Gil Peyrot 2017-07-20 20:03:15 +01:00
parent 0fcbf11644
commit 1f43cd934b
35 changed files with 86 additions and 87 deletions

View file

@ -22,3 +22,4 @@ sha2 = "0.6.0"
sha3 = "0.6.0" sha3 = "0.6.0"
blake2 = "0.6.0" blake2 = "0.6.0"
chrono = "0.4.0" chrono = "0.4.0"
try_from = "0.2.2"

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use minidom::Element; use minidom::Element;
@ -16,7 +16,7 @@ use ns;
pub struct Attention; pub struct Attention;
impl TryFrom<Element> for Attention { impl TryFrom<Element> for Attention {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<Attention, Error> { fn try_from(elem: Element) -> Result<Attention, Error> {
if !elem.is("attention", ns::ATTENTION) { if !elem.is("attention", ns::ATTENTION) {
@ -39,7 +39,7 @@ impl Into<Element> for Attention {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::convert::TryFrom; use try_from::TryFrom;
use minidom::Element; use minidom::Element;
use error::Error; use error::Error;
use super::Attention; use super::Attention;

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use disco::{Feature, Identity, DiscoInfoResult, DiscoInfoQuery}; use disco::{Feature, Identity, DiscoInfoResult, DiscoInfoQuery};
use data_forms::DataForm; use data_forms::DataForm;
@ -29,7 +29,7 @@ pub struct Caps {
} }
impl TryFrom<Element> for Caps { impl TryFrom<Element> for Caps {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<Caps, Error> { fn try_from(elem: Element) -> Result<Caps, Error> {
if !elem.is("c", ns::CAPS) { if !elem.is("c", ns::CAPS) {

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use minidom::Element; use minidom::Element;
@ -22,7 +22,7 @@ pub enum ChatState {
} }
impl TryFrom<Element> for ChatState { impl TryFrom<Element> for ChatState {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<ChatState, Error> { fn try_from(elem: Element) -> Result<ChatState, Error> {
if elem.ns() != Some(ns::CHATSTATES) { if elem.ns() != Some(ns::CHATSTATES) {

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use std::str::FromStr; use std::str::FromStr;
use minidom::{Element, IntoElements, IntoAttributeValue, ElementEmitter}; use minidom::{Element, IntoElements, IntoAttributeValue, ElementEmitter};
@ -103,7 +103,7 @@ pub struct DataForm {
} }
impl TryFrom<Element> for DataForm { impl TryFrom<Element> for DataForm {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<DataForm, Error> { fn try_from(elem: Element) -> Result<DataForm, Error> {
if !elem.is("x", ns::DATA_FORMS) { if !elem.is("x", ns::DATA_FORMS) {

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use minidom::Element; use minidom::Element;
use chrono::{DateTime, FixedOffset}; use chrono::{DateTime, FixedOffset};
@ -22,7 +22,7 @@ pub struct Delay {
} }
impl TryFrom<Element> for Delay { impl TryFrom<Element> for Delay {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<Delay, Error> { fn try_from(elem: Element) -> Result<Delay, Error> {
if !elem.is("delay", ns::DELAY) { if !elem.is("delay", ns::DELAY) {

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use minidom::{Element, IntoElements, ElementEmitter}; use minidom::{Element, IntoElements, ElementEmitter};
@ -19,7 +19,7 @@ pub struct DiscoInfoQuery {
} }
impl TryFrom<Element> for DiscoInfoQuery { impl TryFrom<Element> for DiscoInfoQuery {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<DiscoInfoQuery, Error> { fn try_from(elem: Element) -> Result<DiscoInfoQuery, Error> {
if !elem.is("query", ns::DISCO_INFO) { if !elem.is("query", ns::DISCO_INFO) {
@ -103,7 +103,7 @@ pub struct DiscoInfoResult {
} }
impl TryFrom<Element> for DiscoInfoResult { impl TryFrom<Element> for DiscoInfoResult {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<DiscoInfoResult, Error> { fn try_from(elem: Element) -> Result<DiscoInfoResult, Error> {
if !elem.is("query", ns::DISCO_INFO) { if !elem.is("query", ns::DISCO_INFO) {

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use disco::{Feature, Identity, DiscoInfoResult, DiscoInfoQuery}; use disco::{Feature, Identity, DiscoInfoResult, DiscoInfoQuery};
use data_forms::DataForm; use data_forms::DataForm;
@ -26,7 +26,7 @@ pub struct ECaps2 {
} }
impl TryFrom<Element> for ECaps2 { impl TryFrom<Element> for ECaps2 {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<ECaps2, Error> { fn try_from(elem: Element) -> Result<ECaps2, Error> {
if !elem.is("c", ns::ECAPS2) { if !elem.is("c", ns::ECAPS2) {

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use minidom::Element; use minidom::Element;
@ -19,7 +19,7 @@ pub struct ExplicitMessageEncryption {
} }
impl TryFrom<Element> for ExplicitMessageEncryption { impl TryFrom<Element> for ExplicitMessageEncryption {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<ExplicitMessageEncryption, Error> { fn try_from(elem: Element) -> Result<ExplicitMessageEncryption, Error> {
if !elem.is("encryption", ns::EME) { if !elem.is("encryption", ns::EME) {

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use minidom::Element; use minidom::Element;
@ -23,7 +23,7 @@ pub struct Forwarded {
} }
impl TryFrom<Element> for Forwarded { impl TryFrom<Element> for Forwarded {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<Forwarded, Error> { fn try_from(elem: Element) -> Result<Forwarded, Error> {
if !elem.is("forwarded", ns::FORWARD) { if !elem.is("forwarded", ns::FORWARD) {

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use std::str::FromStr; use std::str::FromStr;
use minidom::{Element, IntoAttributeValue}; use minidom::{Element, IntoAttributeValue};
@ -75,7 +75,7 @@ pub struct Hash {
} }
impl TryFrom<Element> for Hash { impl TryFrom<Element> for Hash {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<Hash, Error> { fn try_from(elem: Element) -> Result<Hash, Error> {
if !elem.is("hash", ns::HASHES) { if !elem.is("hash", ns::HASHES) {

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use std::str::FromStr; use std::str::FromStr;
use minidom::{Element, IntoAttributeValue}; use minidom::{Element, IntoAttributeValue};
@ -37,7 +37,7 @@ pub enum IBB {
} }
impl TryFrom<Element> for IBB { impl TryFrom<Element> for IBB {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<IBB, Error> { fn try_from(elem: Element) -> Result<IBB, Error> {
if elem.is("open", ns::IBB) { if elem.is("open", ns::IBB) {

View file

@ -5,7 +5,7 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::collections::HashMap; use std::collections::HashMap;
use std::convert::TryFrom; use try_from::TryFrom;
use minidom::{Element, IntoElements, ElementEmitter}; use minidom::{Element, IntoElements, ElementEmitter};
@ -26,7 +26,7 @@ pub struct Query {
} }
impl TryFrom<Element> for Query { impl TryFrom<Element> for Query {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<Query, Error> { fn try_from(elem: Element) -> Result<Query, Error> {
if !elem.is("query", ns::REGISTER) { if !elem.is("query", ns::REGISTER) {

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use minidom::Element; use minidom::Element;
use chrono::{DateTime, FixedOffset}; use chrono::{DateTime, FixedOffset};
@ -19,7 +19,7 @@ pub struct Idle {
} }
impl TryFrom<Element> for Idle { impl TryFrom<Element> for Idle {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<Idle, Error> { fn try_from(elem: Element) -> Result<Idle, Error> {
if !elem.is("idle", ns::IDLE) { if !elem.is("idle", ns::IDLE) {

View file

@ -5,7 +5,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use minidom::Element; use minidom::Element;
use minidom::IntoAttributeValue; use minidom::IntoAttributeValue;
@ -61,7 +61,7 @@ pub enum IqResultPayload {
} }
impl TryFrom<Element> for IqGetPayload { impl TryFrom<Element> for IqGetPayload {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<IqGetPayload, Error> { fn try_from(elem: Element) -> Result<IqGetPayload, Error> {
Ok(match (elem.name().as_ref(), elem.ns().unwrap().as_ref()) { Ok(match (elem.name().as_ref(), elem.ns().unwrap().as_ref()) {
@ -98,7 +98,7 @@ impl Into<Element> for IqGetPayload {
} }
impl TryFrom<Element> for IqSetPayload { impl TryFrom<Element> for IqSetPayload {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<IqSetPayload, Error> { fn try_from(elem: Element) -> Result<IqSetPayload, Error> {
Ok(match (elem.name().as_ref(), elem.ns().unwrap().as_ref()) { Ok(match (elem.name().as_ref(), elem.ns().unwrap().as_ref()) {
@ -137,7 +137,7 @@ impl Into<Element> for IqSetPayload {
} }
impl TryFrom<Element> for IqResultPayload { impl TryFrom<Element> for IqResultPayload {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<IqResultPayload, Error> { fn try_from(elem: Element) -> Result<IqResultPayload, Error> {
Ok(match (elem.name().as_ref(), elem.ns().unwrap().as_ref()) { Ok(match (elem.name().as_ref(), elem.ns().unwrap().as_ref()) {
@ -199,7 +199,7 @@ pub struct Iq {
} }
impl TryFrom<Element> for Iq { impl TryFrom<Element> for Iq {
type Error = Error; type Err = Error;
fn try_from(root: Element) -> Result<Iq, Error> { fn try_from(root: Element) -> Result<Iq, Error> {
if !root.is("iq", ns::JABBER_CLIENT) { if !root.is("iq", ns::JABBER_CLIENT) {

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use std::str::FromStr; use std::str::FromStr;
use minidom::{Element, IntoElements, IntoAttributeValue, ElementEmitter}; use minidom::{Element, IntoElements, IntoAttributeValue, ElementEmitter};
@ -57,7 +57,7 @@ pub struct Content {
} }
impl TryFrom<Element> for Content { impl TryFrom<Element> for Content {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<Content, Error> { fn try_from(elem: Element) -> Result<Content, Error> {
if !elem.is("content", ns::JINGLE) { if !elem.is("content", ns::JINGLE) {
@ -196,7 +196,7 @@ pub struct ReasonElement {
} }
impl TryFrom<Element> for ReasonElement { impl TryFrom<Element> for ReasonElement {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<ReasonElement, Error> { fn try_from(elem: Element) -> Result<ReasonElement, Error> {
if !elem.is("reason", ns::JINGLE) { if !elem.is("reason", ns::JINGLE) {
@ -261,7 +261,7 @@ pub struct Jingle {
} }
impl TryFrom<Element> for Jingle { impl TryFrom<Element> for Jingle {
type Error = Error; type Err = Error;
fn try_from(root: Element) -> Result<Jingle, Error> { fn try_from(root: Element) -> Result<Jingle, Error> {
if !root.is("jingle", ns::JINGLE) { if !root.is("jingle", ns::JINGLE) {

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use hashes::Hash; use hashes::Hash;
@ -85,7 +85,7 @@ impl IntoElements for Received {
} }
impl TryFrom<Element> for Description { impl TryFrom<Element> for Description {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<Description, Error> { fn try_from(elem: Element) -> Result<Description, Error> {
if !elem.is("description", ns::JINGLE_FT) { if !elem.is("description", ns::JINGLE_FT) {

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use std::str::FromStr; use std::str::FromStr;
use minidom::{Element, IntoAttributeValue}; use minidom::{Element, IntoAttributeValue};
@ -25,7 +25,7 @@ pub struct Transport {
} }
impl TryFrom<Element> for Transport { impl TryFrom<Element> for Transport {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<Transport, Error> { fn try_from(elem: Element) -> Result<Transport, Error> {
if !elem.is("transport", ns::JINGLE_IBB) { if !elem.is("transport", ns::JINGLE_IBB) {

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use minidom::Element; use minidom::Element;
@ -44,7 +44,7 @@ fn check_empty_and_get_sid(elem: Element) -> Result<SessionId, Error> {
} }
impl TryFrom<Element> for JingleMI { impl TryFrom<Element> for JingleMI {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<JingleMI, Error> { fn try_from(elem: Element) -> Result<JingleMI, Error> {
if elem.ns() != Some(ns::JINGLE_MESSAGE) { if elem.ns() != Some(ns::JINGLE_MESSAGE) {

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use std::str::FromStr; use std::str::FromStr;
use minidom::{Element, IntoAttributeValue}; use minidom::{Element, IntoAttributeValue};
@ -73,7 +73,7 @@ pub struct Transport {
} }
impl TryFrom<Element> for Transport { impl TryFrom<Element> for Transport {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<Transport, Error> { fn try_from(elem: Element) -> Result<Transport, Error> {
if elem.is("transport", ns::JINGLE_S5B) { if elem.is("transport", ns::JINGLE_S5B) {

View file

@ -13,8 +13,6 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
#![feature(try_from)]
extern crate minidom; extern crate minidom;
extern crate jid; extern crate jid;
extern crate base64; extern crate base64;
@ -24,6 +22,7 @@ extern crate sha2;
extern crate sha3; extern crate sha3;
extern crate blake2; extern crate blake2;
extern crate chrono; extern crate chrono;
extern crate try_from;
macro_rules! get_attr { macro_rules! get_attr {
($elem:ident, $attr:tt, $type:tt) => ( ($elem:ident, $attr:tt, $type:tt) => (

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use std::str::FromStr; use std::str::FromStr;
use minidom::{Element, IntoAttributeValue}; use minidom::{Element, IntoAttributeValue};
@ -53,7 +53,7 @@ pub struct Prefs {
} }
impl TryFrom<Element> for Query { impl TryFrom<Element> for Query {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<Query, Error> { fn try_from(elem: Element) -> Result<Query, Error> {
if !elem.is("query", ns::MAM) { if !elem.is("query", ns::MAM) {
@ -77,7 +77,7 @@ impl TryFrom<Element> for Query {
} }
impl TryFrom<Element> for Result_ { impl TryFrom<Element> for Result_ {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<Result_, Error> { fn try_from(elem: Element) -> Result<Result_, Error> {
if !elem.is("result", ns::MAM) { if !elem.is("result", ns::MAM) {
@ -103,7 +103,7 @@ impl TryFrom<Element> for Result_ {
} }
impl TryFrom<Element> for Fin { impl TryFrom<Element> for Fin {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<Fin, Error> { fn try_from(elem: Element) -> Result<Fin, Error> {
if !elem.is("fin", ns::MAM) { if !elem.is("fin", ns::MAM) {
@ -129,7 +129,7 @@ impl TryFrom<Element> for Fin {
} }
impl TryFrom<Element> for Prefs { impl TryFrom<Element> for Prefs {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<Prefs, Error> { fn try_from(elem: Element) -> Result<Prefs, Error> {
if !elem.is("prefs", ns::MAM) { if !elem.is("prefs", ns::MAM) {

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use minidom::{Element, IntoElements, ElementEmitter}; use minidom::{Element, IntoElements, ElementEmitter};
@ -42,7 +42,7 @@ pub struct MediaElement {
} }
impl TryFrom<Element> for MediaElement { impl TryFrom<Element> for MediaElement {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<MediaElement, Error> { fn try_from(elem: Element) -> Result<MediaElement, Error> {
if !elem.is("media", ns::MEDIA_ELEMENT) { if !elem.is("media", ns::MEDIA_ELEMENT) {

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use std::str::FromStr; use std::str::FromStr;
use std::collections::BTreeMap; use std::collections::BTreeMap;
@ -43,7 +43,7 @@ pub enum MessagePayload {
} }
impl TryFrom<Element> for MessagePayload { impl TryFrom<Element> for MessagePayload {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<MessagePayload, Error> { fn try_from(elem: Element) -> Result<MessagePayload, Error> {
Ok(match (elem.name().as_ref(), elem.ns().unwrap().as_ref()) { Ok(match (elem.name().as_ref(), elem.ns().unwrap().as_ref()) {
@ -143,7 +143,7 @@ impl Message {
} }
impl TryFrom<Element> for Message { impl TryFrom<Element> for Message {
type Error = Error; type Err = Error;
fn try_from(root: Element) -> Result<Message, Error> { fn try_from(root: Element) -> Result<Message, Error> {
if !root.is("message", ns::JABBER_CLIENT) { if !root.is("message", ns::JABBER_CLIENT) {

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use minidom::Element; use minidom::Element;
@ -18,7 +18,7 @@ pub struct Replace {
} }
impl TryFrom<Element> for Replace { impl TryFrom<Element> for Replace {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<Replace, Error> { fn try_from(elem: Element) -> Result<Replace, Error> {
if !elem.is("replace", ns::MESSAGE_CORRECT) { if !elem.is("replace", ns::MESSAGE_CORRECT) {

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use minidom::Element; use minidom::Element;
@ -18,7 +18,7 @@ pub struct Muc {
} }
impl TryFrom<Element> for Muc { impl TryFrom<Element> for Muc {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<Muc, Error> { fn try_from(elem: Element) -> Result<Muc, Error> {
if !elem.is("x", ns::MUC) { if !elem.is("x", ns::MUC) {

View file

@ -4,8 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::{TryFrom, TryInto};
use std::convert::TryInto;
use std::str::FromStr; use std::str::FromStr;
use minidom::{Element, IntoElements, IntoAttributeValue, ElementEmitter}; use minidom::{Element, IntoElements, IntoAttributeValue, ElementEmitter};
@ -74,7 +73,7 @@ pub enum Status {
} }
impl TryFrom<Element> for Status { impl TryFrom<Element> for Status {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<Status, Error> { fn try_from(elem: Element) -> Result<Status, Error> {
if !elem.is("status", ns::MUC_USER) { if !elem.is("status", ns::MUC_USER) {
@ -160,7 +159,7 @@ pub enum Actor {
} }
impl TryFrom<Element> for Actor { impl TryFrom<Element> for Actor {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<Actor, Error> { fn try_from(elem: Element) -> Result<Actor, Error> {
if !elem.is("actor", ns::MUC_USER) { if !elem.is("actor", ns::MUC_USER) {
@ -210,7 +209,7 @@ pub struct Continue {
} }
impl TryFrom<Element> for Continue { impl TryFrom<Element> for Continue {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<Continue, Error> { fn try_from(elem: Element) -> Result<Continue, Error> {
if !elem.is("continue", ns::MUC_USER) { if !elem.is("continue", ns::MUC_USER) {
@ -247,7 +246,7 @@ impl IntoElements for Continue {
pub struct Reason(String); pub struct Reason(String);
impl TryFrom<Element> for Reason { impl TryFrom<Element> for Reason {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<Reason, Error> { fn try_from(elem: Element) -> Result<Reason, Error> {
if !elem.is("reason", ns::MUC_USER) { if !elem.is("reason", ns::MUC_USER) {
@ -305,7 +304,7 @@ pub struct Item {
} }
impl TryFrom<Element> for Item { impl TryFrom<Element> for Item {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<Item, Error> { fn try_from(elem: Element) -> Result<Item, Error> {
if !elem.is("item", ns::MUC_USER) { if !elem.is("item", ns::MUC_USER) {
@ -374,7 +373,7 @@ pub struct MucUser {
} }
impl TryFrom<Element> for MucUser { impl TryFrom<Element> for MucUser {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<MucUser, Error> { fn try_from(elem: Element) -> Result<MucUser, Error> {
if !elem.is("x", ns::MUC_USER) { if !elem.is("x", ns::MUC_USER) {

View file

@ -5,7 +5,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use minidom::Element; use minidom::Element;
@ -17,7 +17,7 @@ use ns;
pub struct Ping; pub struct Ping;
impl TryFrom<Element> for Ping { impl TryFrom<Element> for Ping {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<Ping, Error> { fn try_from(elem: Element) -> Result<Ping, Error> {
if !elem.is("ping", ns::PING) { if !elem.is("ping", ns::PING) {

View file

@ -5,7 +5,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use std::str::FromStr; use std::str::FromStr;
use std::collections::BTreeMap; use std::collections::BTreeMap;
@ -91,7 +91,7 @@ pub enum PresencePayload {
} }
impl TryFrom<Element> for PresencePayload { impl TryFrom<Element> for PresencePayload {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<PresencePayload, Error> { fn try_from(elem: Element) -> Result<PresencePayload, Error> {
Ok(match (elem.name().as_ref(), elem.ns().unwrap().as_ref()) { Ok(match (elem.name().as_ref(), elem.ns().unwrap().as_ref()) {
@ -214,7 +214,7 @@ impl Presence {
} }
impl TryFrom<Element> for Presence { impl TryFrom<Element> for Presence {
type Error = Error; type Err = Error;
fn try_from(root: Element) -> Result<Presence, Error> { fn try_from(root: Element) -> Result<Presence, Error> {
if !root.is("presence", ns::JABBER_CLIENT) { if !root.is("presence", ns::JABBER_CLIENT) {

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use std::str::FromStr; use std::str::FromStr;
use minidom::{Element, IntoElements, IntoAttributeValue, ElementEmitter}; use minidom::{Element, IntoElements, IntoAttributeValue, ElementEmitter};
@ -138,7 +138,7 @@ fn parse_items(elem: Element, node: String) -> Result<PubSubEvent, Error> {
} }
impl TryFrom<Element> for PubSubEvent { impl TryFrom<Element> for PubSubEvent {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<PubSubEvent, Error> { fn try_from(elem: Element) -> Result<PubSubEvent, Error> {
if !elem.is("event", ns::PUBSUB_EVENT) { if !elem.is("event", ns::PUBSUB_EVENT) {

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use minidom::Element; use minidom::Element;
@ -19,7 +19,7 @@ pub enum Receipt {
} }
impl TryFrom<Element> for Receipt { impl TryFrom<Element> for Receipt {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<Receipt, Error> { fn try_from(elem: Element) -> Result<Receipt, Error> {
for _ in elem.children() { for _ in elem.children() {

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use std::str::FromStr; use std::str::FromStr;
use minidom::{Element, IntoElements, IntoAttributeValue, ElementEmitter}; use minidom::{Element, IntoElements, IntoAttributeValue, ElementEmitter};
@ -32,7 +32,7 @@ pub struct Item {
} }
impl TryFrom<Element> for Item { impl TryFrom<Element> for Item {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<Item, Error> { fn try_from(elem: Element) -> Result<Item, Error> {
if !elem.is("item", ns::ROSTER) { if !elem.is("item", ns::ROSTER) {
@ -83,7 +83,7 @@ pub struct Roster {
} }
impl TryFrom<Element> for Roster { impl TryFrom<Element> for Roster {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<Roster, Error> { fn try_from(elem: Element) -> Result<Roster, Error> {
if !elem.is("query", ns::ROSTER) { if !elem.is("query", ns::ROSTER) {

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use minidom::Element; use minidom::Element;
@ -25,7 +25,7 @@ pub struct Set {
} }
impl TryFrom<Element> for Set { impl TryFrom<Element> for Set {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<Set, Error> { fn try_from(elem: Element) -> Result<Set, Error> {
if !elem.is("set", ns::RSM) { if !elem.is("set", ns::RSM) {

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use std::str::FromStr; use std::str::FromStr;
use std::collections::BTreeMap; use std::collections::BTreeMap;
@ -122,7 +122,7 @@ pub struct StanzaError {
} }
impl TryFrom<Element> for StanzaError { impl TryFrom<Element> for StanzaError {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<StanzaError, Error> { fn try_from(elem: Element) -> Result<StanzaError, Error> {
if !elem.is("error", ns::JABBER_CLIENT) { if !elem.is("error", ns::JABBER_CLIENT) {

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::convert::TryFrom; use try_from::TryFrom;
use minidom::Element; use minidom::Element;
use jid::Jid; use jid::Jid;
@ -25,7 +25,7 @@ pub enum StanzaId {
} }
impl TryFrom<Element> for StanzaId { impl TryFrom<Element> for StanzaId {
type Error = Error; type Err = Error;
fn try_from(elem: Element) -> Result<StanzaId, Error> { fn try_from(elem: Element) -> Result<StanzaId, Error> {
let is_stanza_id = elem.is("stanza-id", ns::SID); let is_stanza_id = elem.is("stanza-id", ns::SID);