From 017fb0fbd1d4c803c865d2abd23e7305bcceeb74 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Tue, 26 Feb 2019 20:21:26 +0100 Subject: [PATCH] stanza_error: Add a constructor. --- src/stanza_error.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/stanza_error.rs b/src/stanza_error.rs index 3488b9c..4c09eea 100644 --- a/src/stanza_error.rs +++ b/src/stanza_error.rs @@ -215,6 +215,26 @@ pub struct StanzaError { impl MessagePayload for StanzaError {} impl PresencePayload for StanzaError {} +impl StanzaError { + /// Create a new `` with the according content. + pub fn new(type_: ErrorType, defined_condition: DefinedCondition, lang: L, text: T) -> StanzaError + where L: Into, + T: Into, + { + StanzaError { + type_, + by: None, + defined_condition, + texts: { + let mut map = BTreeMap::new(); + map.insert(lang.into(), text.into()); + map + }, + other: None, + } + } +} + impl TryFrom for StanzaError { type Err = Error;