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 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more