sparkplug_rs/
topic_namespace.rs1use std::error::Error;
2use std::fmt::{Debug, Display, Formatter};
3use std::str::FromStr;
4
5#[derive(Debug, Clone, PartialEq)]
24pub enum TopicNamespace {
25 SPAV1_0,
27 SPBV1_0,
29}
30
31impl ToString for TopicNamespace {
32 fn to_string(&self) -> String {
33 match self {
34 TopicNamespace::SPAV1_0 => "spAv1.0".to_string(),
35 TopicNamespace::SPBV1_0 => "spBv1.0".to_string(),
36 }
37 }
38}
39
40pub struct TopicNamespaceParseError;
41
42impl Debug for TopicNamespaceParseError {
43 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
44 Display::fmt(self, f)
45 }
46}
47
48impl Display for TopicNamespaceParseError {
49 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
50 f.write_str("Error parsing topic's namespace")
51 }
52}
53
54impl Error for TopicNamespaceParseError {}
55
56impl FromStr for TopicNamespace {
57 type Err = TopicNamespaceParseError;
58
59 fn from_str(s: &str) -> Result<Self, Self::Err> {
60 match s {
61 "spAv1.0" => Ok(TopicNamespace::SPAV1_0),
62 "spBv1.0" => Ok(TopicNamespace::SPBV1_0),
63 _ => Err(TopicNamespaceParseError),
64 }
65 }
66}