parsers: port enums over to derive macros
This commit is contained in:
parent
c028c3b91a
commit
6afd0ef52f
7 changed files with 563 additions and 428 deletions
|
|
@ -4,28 +4,36 @@
|
|||
// 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 xso::{AsXml, FromXml};
|
||||
|
||||
use crate::message::MessagePayload;
|
||||
use crate::ns;
|
||||
|
||||
generate_element_enum!(
|
||||
/// Enum representing chatstate elements part of the
|
||||
/// `http://jabber.org/protocol/chatstates` namespace.
|
||||
ChatState, "chatstate", CHATSTATES, {
|
||||
/// `<active xmlns='http://jabber.org/protocol/chatstates'/>`
|
||||
Active => "active",
|
||||
/// Enum representing chatstate elements part of the
|
||||
/// `http://jabber.org/protocol/chatstates` namespace.
|
||||
#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
|
||||
#[xml(namespace = ns::CHATSTATES, exhaustive)]
|
||||
pub enum ChatState {
|
||||
/// `<active xmlns='http://jabber.org/protocol/chatstates'/>`
|
||||
#[xml(name = "active")]
|
||||
Active,
|
||||
|
||||
/// `<composing xmlns='http://jabber.org/protocol/chatstates'/>`
|
||||
Composing => "composing",
|
||||
/// `<composing xmlns='http://jabber.org/protocol/chatstates'/>`
|
||||
#[xml(name = "composing")]
|
||||
Composing,
|
||||
|
||||
/// `<gone xmlns='http://jabber.org/protocol/chatstates'/>`
|
||||
Gone => "gone",
|
||||
/// `<gone xmlns='http://jabber.org/protocol/chatstates'/>`
|
||||
#[xml(name = "gone")]
|
||||
Gone,
|
||||
|
||||
/// `<inactive xmlns='http://jabber.org/protocol/chatstates'/>`
|
||||
Inactive => "inactive",
|
||||
/// `<inactive xmlns='http://jabber.org/protocol/chatstates'/>`
|
||||
#[xml(name = "inactive")]
|
||||
Inactive,
|
||||
|
||||
/// `<paused xmlns='http://jabber.org/protocol/chatstates'/>`
|
||||
Paused => "paused",
|
||||
}
|
||||
);
|
||||
/// `<paused xmlns='http://jabber.org/protocol/chatstates'/>`
|
||||
#[xml(name = "paused")]
|
||||
Paused,
|
||||
}
|
||||
|
||||
impl MessagePayload for ChatState {}
|
||||
|
||||
|
|
@ -59,7 +67,7 @@ mod tests {
|
|||
FromElementError::Invalid(Error::Other(string)) => string,
|
||||
_ => panic!(),
|
||||
};
|
||||
assert_eq!(message, "This is not a chatstate element.");
|
||||
assert_eq!(message, "This is not a ChatState element.");
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "disable-validation"))]
|
||||
|
|
@ -73,7 +81,7 @@ mod tests {
|
|||
FromElementError::Invalid(Error::Other(string)) => string,
|
||||
_ => panic!(),
|
||||
};
|
||||
assert_eq!(message, "Unknown child in chatstate element.");
|
||||
assert_eq!(message, "Unknown child in ChatState::Gone element.");
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "disable-validation"))]
|
||||
|
|
@ -87,7 +95,7 @@ mod tests {
|
|||
FromElementError::Invalid(Error::Other(string)) => string,
|
||||
_ => panic!(),
|
||||
};
|
||||
assert_eq!(message, "Unknown attribute in chatstate element.");
|
||||
assert_eq!(message, "Unknown attribute in ChatState::Inactive element.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Reference in a new issue