use std::error::Error;
use std::fmt::{Debug, Display, Formatter};
use std::str::FromStr;
#[derive(Debug, Clone, PartialEq)]
pub enum TopicNamespace {
SPAV1_0,
SPBV1_0,
}
impl ToString for TopicNamespace {
fn to_string(&self) -> String {
match self {
TopicNamespace::SPAV1_0 => "spAv1.0".to_string(),
TopicNamespace::SPBV1_0 => "spBv1.0".to_string(),
}
}
}
pub struct TopicNamespaceParseError;
impl Debug for TopicNamespaceParseError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Display::fmt(self, f)
}
}
impl Display for TopicNamespaceParseError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.write_str("Error parsing topic's namespace")
}
}
impl Error for TopicNamespaceParseError {}
impl FromStr for TopicNamespace {
type Err = TopicNamespaceParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"spAv1.0" => Ok(TopicNamespace::SPAV1_0),
"spBv1.0" => Ok(TopicNamespace::SPBV1_0),
_ => Err(TopicNamespaceParseError),
}
}
}