diff options
author | 2024-12-04 18:18:37 +0000 | |
---|---|---|
committer | 2024-12-04 18:18:37 +0000 | |
commit | 1b91ff690488b65b552c90bd5392b9a300c8c981 (patch) | |
tree | 9c290f69b26eba0393d7bbc05ba29c28ea74a26e /src/stanza/client/error.rs | |
parent | 03764f8cedb3f0a55a61be0f0a59faaa6357a83a (diff) | |
download | luz-1b91ff690488b65b552c90bd5392b9a300c8c981.tar.gz luz-1b91ff690488b65b552c90bd5392b9a300c8c981.tar.bz2 luz-1b91ff690488b65b552c90bd5392b9a300c8c981.zip |
use cargo workspace
Diffstat (limited to 'src/stanza/client/error.rs')
-rw-r--r-- | src/stanza/client/error.rs | 83 |
1 files changed, 0 insertions, 83 deletions
diff --git a/src/stanza/client/error.rs b/src/stanza/client/error.rs deleted file mode 100644 index 545b9a7..0000000 --- a/src/stanza/client/error.rs +++ /dev/null @@ -1,83 +0,0 @@ -use std::str::FromStr; - -use peanuts::element::{FromElement, IntoElement}; -use peanuts::{DeserializeError, Element}; - -use crate::stanza::stanza_error::Error as StanzaError; -use crate::stanza::stanza_error::Text; - -use super::XMLNS; - -#[derive(Clone, Debug)] -pub struct Error { - by: Option<String>, - r#type: ErrorType, - // children (sequence) - error: StanzaError, - text: Option<Text>, -} - -impl FromElement for Error { - fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult<Self> { - element.check_name("error")?; - element.check_name(XMLNS)?; - - let by = element.attribute_opt("by")?; - let r#type = element.attribute("type")?; - let error = element.pop_child_one()?; - let text = element.pop_child_opt()?; - - Ok(Error { - by, - r#type, - error, - text, - }) - } -} - -impl IntoElement for Error { - fn builder(&self) -> peanuts::element::ElementBuilder { - Element::builder("error", Some(XMLNS)) - .push_attribute_opt("by", self.by.clone()) - .push_attribute("type", self.r#type) - .push_child(self.error.clone()) - .push_child_opt(self.text.clone()) - } -} - -#[derive(Copy, Clone, Debug)] -pub enum ErrorType { - Auth, - Cancel, - Continue, - Modify, - Wait, -} - -impl FromStr for ErrorType { - type Err = DeserializeError; - - fn from_str(s: &str) -> Result<Self, Self::Err> { - match s { - "auth" => Ok(ErrorType::Auth), - "cancel" => Ok(ErrorType::Cancel), - "continue" => Ok(ErrorType::Continue), - "modify" => Ok(ErrorType::Modify), - "wait" => Ok(ErrorType::Wait), - _ => Err(DeserializeError::FromStr(s.to_string())), - } - } -} - -impl ToString for ErrorType { - fn to_string(&self) -> String { - match self { - ErrorType::Auth => "auth".to_string(), - ErrorType::Cancel => "cancel".to_string(), - ErrorType::Continue => "continue".to_string(), - ErrorType::Modify => "modify".to_string(), - ErrorType::Wait => "wait".to_string(), - } - } -} |