stanza_error: Add a constructor.

This commit is contained in:
Emmanuel Gil Peyrot 2019-02-26 20:21:26 +01:00
parent ab28824b1a
commit 017fb0fbd1

View file

@ -215,6 +215,26 @@ pub struct StanzaError {
impl MessagePayload for StanzaError {}
impl PresencePayload for StanzaError {}
impl StanzaError {
/// Create a new `<error/>` with the according content.
pub fn new<L, T>(type_: ErrorType, defined_condition: DefinedCondition, lang: L, text: T) -> StanzaError
where L: Into<Lang>,
T: Into<String>,
{
StanzaError {
type_,
by: None,
defined_condition,
texts: {
let mut map = BTreeMap::new();
map.insert(lang.into(), text.into());
map
},
other: None,
}
}
}
impl TryFrom<Element> for StanzaError {
type Err = Error;