use std::error::Error;
use std::fmt;
use std::sync::Arc;
#[derive(Debug, Clone)]
pub struct ConferenceInfoError {
kind: ConferenceInfoErrorKind,
source: Arc<dyn Error + Send + Sync>,
}
impl ConferenceInfoError {
pub(super) fn new(
kind: ConferenceInfoErrorKind,
source: impl Error + Send + Sync + 'static,
) -> Self {
ConferenceInfoError {
kind,
source: Arc::new(source),
}
}
pub fn kind(&self) -> ConferenceInfoErrorKind {
self.kind
}
}
impl fmt::Display for ConferenceInfoError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "conference-info: {}", self.kind)
}
}
impl Error for ConferenceInfoError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
Some(&*self.source)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ConferenceInfoErrorKind {
Read,
Normalize,
NotUtf8,
Deserialize,
Serialize,
}
impl ConferenceInfoErrorKind {
pub fn as_str(self) -> &'static str {
match self {
ConferenceInfoErrorKind::Read => "ill-formed-xml",
ConferenceInfoErrorKind::Normalize => "normalize-failed",
ConferenceInfoErrorKind::NotUtf8 => "not-utf8",
ConferenceInfoErrorKind::Deserialize => "schema-mismatch",
ConferenceInfoErrorKind::Serialize => "serialize-failed",
}
}
}
impl fmt::Display for ConferenceInfoErrorKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}