aboutsummaryrefslogtreecommitdiffstats
path: root/stanza/src/stream.rs
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@bunny.garden>2025-02-25 20:30:44 +0000
committerLibravatar cel 🌸 <cel@bunny.garden>2025-02-25 20:30:44 +0000
commit53ea2951ae49d1617a6a7de760d391fe0ea2b7a9 (patch)
tree17e8484a9bc6b05e320d77dd1c3f668af41c3006 /stanza/src/stream.rs
parentb859cd7f78495da90b947febabefdff82c02deb9 (diff)
downloadluz-53ea2951ae49d1617a6a7de760d391fe0ea2b7a9.tar.gz
luz-53ea2951ae49d1617a6a7de760d391fe0ea2b7a9.tar.bz2
luz-53ea2951ae49d1617a6a7de760d391fe0ea2b7a9.zip
implement Error for stanza crate error types
Diffstat (limited to 'stanza/src/stream.rs')
-rw-r--r--stanza/src/stream.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/stanza/src/stream.rs b/stanza/src/stream.rs
index 069dcd1..60b13bc 100644
--- a/stanza/src/stream.rs
+++ b/stanza/src/stream.rs
@@ -1,6 +1,9 @@
+use std::fmt::Display;
+
use jid::JID;
use peanuts::element::{ElementBuilder, FromElement, IntoElement};
use peanuts::Element;
+use thiserror::Error;
use crate::bind;
@@ -176,12 +179,24 @@ impl FromElement for Feature {
}
}
-#[derive(Debug)]
+#[derive(Error, Debug)]
pub struct Error {
error: StreamError,
text: Option<Text>,
}
+impl Display for Error {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "{}", self.error)?;
+ if let Some(text) = &self.text {
+ if let Some(text) = &text.text {
+ write!(f, ": {}", text)?;
+ }
+ }
+ Ok(())
+ }
+}
+
impl FromElement for Error {
fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
element.check_name("error")?;