Skip to main content

mqtt_topic_engine/
error.rs

1//! Error types and utilities for the topic module
2//!
3//! This module contains the composite error type and shared constants
4//! for the entire topic module, while individual error types remain
5//! in their respective modules.
6
7use thiserror::Error;
8
9#[cfg(feature = "router")]
10use crate::topic_matcher::TopicMatcherError;
11use crate::topic_pattern_item::TopicPatternError;
12use crate::topic_pattern_path::TopicFormatError;
13#[cfg(feature = "router")]
14use crate::topic_router::TopicRouterError;
15
16/// Comprehensive error type for all topic-related operations
17///
18/// This enum aggregates all possible errors that can occur within the topic module,
19/// providing a single error type for the public API while maintaining detailed
20/// error information from each submodule.
21#[derive(Error, Debug, Clone, PartialEq, Eq)]
22pub enum TopicError {
23	/// Topic pattern parsing or validation error
24	#[error("Topic pattern error: {0}")]
25	Pattern(#[from] TopicPatternError),
26
27	/// Topic formatting error when substituting parameters
28	#[error("Topic format error: {0}")]
29	Format(#[from] TopicFormatError),
30
31	/// Topic matching operation error
32	#[cfg(feature = "router")]
33	#[error("Topic matcher error: {0}")]
34	Matcher(#[from] TopicMatcherError),
35
36	/// Topic routing operation error
37	#[cfg(feature = "router")]
38	#[error("Topic router error: {0}")]
39	Router(#[from] TopicRouterError),
40}
41
42/// Convenient Result type for topic operations
43pub type TopicResult<T> = Result<T, TopicError>;
44
45/// Convenient Result type for pattern operations
46pub type PatternResult<T> = Result<T, TopicPatternError>;
47
48/// Convenient Result type for matcher operations
49#[cfg(feature = "router")]
50pub type MatcherResult<T> = Result<T, TopicMatcherError>;
51
52/// Convenient Result type for router operations
53#[cfg(feature = "router")]
54pub type RouterResult<T> = Result<T, TopicRouterError>;