mqtt-topic-engine 0.2.1

High-performance MQTT topic pattern matching and routing engine
Documentation
//! Error types and utilities for the topic module
//!
//! This module contains the composite error type and shared constants
//! for the entire topic module, while individual error types remain
//! in their respective modules.

use thiserror::Error;

#[cfg(feature = "router")]
use crate::topic_matcher::TopicMatcherError;
use crate::topic_pattern_item::TopicPatternError;
use crate::topic_pattern_path::TopicFormatError;
#[cfg(feature = "router")]
use crate::topic_router::TopicRouterError;

/// Comprehensive error type for all topic-related operations
///
/// This enum aggregates all possible errors that can occur within the topic module,
/// providing a single error type for the public API while maintaining detailed
/// error information from each submodule.
#[derive(Error, Debug, Clone, PartialEq, Eq)]
pub enum TopicError {
	/// Topic pattern parsing or validation error
	#[error("Topic pattern error: {0}")]
	Pattern(#[from] TopicPatternError),

	/// Topic formatting error when substituting parameters
	#[error("Topic format error: {0}")]
	Format(#[from] TopicFormatError),

	/// Topic matching operation error
	#[cfg(feature = "router")]
	#[error("Topic matcher error: {0}")]
	Matcher(#[from] TopicMatcherError),

	/// Topic routing operation error
	#[cfg(feature = "router")]
	#[error("Topic router error: {0}")]
	Router(#[from] TopicRouterError),
}

/// Convenient Result type for topic operations
pub type TopicResult<T> = Result<T, TopicError>;

/// Convenient Result type for pattern operations
pub type PatternResult<T> = Result<T, TopicPatternError>;

/// Convenient Result type for matcher operations
#[cfg(feature = "router")]
pub type MatcherResult<T> = Result<T, TopicMatcherError>;

/// Convenient Result type for router operations
#[cfg(feature = "router")]
pub type RouterResult<T> = Result<T, TopicRouterError>;