pub struct NamespaceValidator {
pub service_prefix: String,
pub device_namespace: String,
pub device_id: Option<String>,
pub allow_system_topics: bool,
pub additional_reserved_prefixes: Vec<String>,
}Expand description
Namespace-based topic validator for hierarchical topic isolation
This validator implements namespace-based topic validation patterns that enforce
hierarchical isolation of topics, commonly used in cloud IoT platforms and
enterprise systems.
The validator enforces:
- Service-reserved topic prefixes (e.g.,
$aws/,$azure/,$company/) - Device-specific namespaces (e.g.,
{prefix}/thing/{device}/,{prefix}/device/{device}/) - System topics (e.g.,
$SYS/)
Examples:
- AWS
IoT:NamespaceValidator::new("$aws", "thing") - Azure
IoT:NamespaceValidator::new("$azure", "device") - Enterprise:
NamespaceValidator::new("$company", "asset")
Fields§
§service_prefix: StringService prefix for reserved topics (e.g., “$aws”, “$azure”, “$company”)
device_namespace: StringDevice namespace identifier (e.g., “thing”, “device”, “asset”)
device_id: Option<String>Optional device identifier for device-specific validation
If set, allows {service_prefix}/{device_namespace}/{device_id}/* topics
allow_system_topics: boolWhether to allow system topics ($SYS/*)
additional_reserved_prefixes: Vec<String>Additional reserved prefixes beyond the service prefix
Implementations§
Source§impl NamespaceValidator
impl NamespaceValidator
Sourcepub fn new(
service_prefix: impl Into<String>,
device_namespace: impl Into<String>,
) -> Self
pub fn new( service_prefix: impl Into<String>, device_namespace: impl Into<String>, ) -> Self
Creates a new namespace validator
§Arguments
service_prefix- The service prefix (e.g., “$aws”, “$azure”)device_namespace- The device namespace pattern (e.g., “thing”, “device”)
Sourcepub fn google_cloud_iot() -> Self
pub fn google_cloud_iot() -> Self
Creates a validator configured for Google Cloud IoT
Sourcepub fn with_device_id(self, device_id: impl Into<String>) -> Self
pub fn with_device_id(self, device_id: impl Into<String>) -> Self
Sets the device identifier for device-specific topic validation
When set, allows topics like {prefix}/{namespace}/{device_id}/* while
rejecting {prefix}/{namespace}/{other_device}/*
Sourcepub fn with_system_topics(self, allow: bool) -> Self
pub fn with_system_topics(self, allow: bool) -> Self
Enables system topics ($SYS/*)
Sourcepub fn with_reserved_prefix(self, prefix: impl Into<String>) -> Self
pub fn with_reserved_prefix(self, prefix: impl Into<String>) -> Self
Adds an additional reserved prefix
Trait Implementations§
Source§impl Clone for NamespaceValidator
impl Clone for NamespaceValidator
Source§fn clone(&self) -> NamespaceValidator
fn clone(&self) -> NamespaceValidator
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for NamespaceValidator
impl Debug for NamespaceValidator
Source§impl TopicValidator for NamespaceValidator
impl TopicValidator for NamespaceValidator
Source§fn validate_topic_name(&self, topic: &str) -> Result<()>
fn validate_topic_name(&self, topic: &str) -> Result<()>
Source§fn validate_topic_filter(&self, filter: &str) -> Result<()>
fn validate_topic_filter(&self, filter: &str) -> Result<()>
Source§fn is_reserved_topic(&self, topic: &str) -> bool
fn is_reserved_topic(&self, topic: &str) -> bool
Source§fn description(&self) -> &'static str
fn description(&self) -> &'static str
Auto Trait Implementations§
impl Freeze for NamespaceValidator
impl RefUnwindSafe for NamespaceValidator
impl Send for NamespaceValidator
impl Sync for NamespaceValidator
impl Unpin for NamespaceValidator
impl UnwindSafe for NamespaceValidator
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)