NamespaceValidator

Struct NamespaceValidator 

Source
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: String

Service prefix for reserved topics (e.g., “$aws”, “$azure”, “$company”)

§device_namespace: String

Device 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: bool

Whether to allow system topics ($SYS/*)

§additional_reserved_prefixes: Vec<String>

Additional reserved prefixes beyond the service prefix

Implementations§

Source§

impl NamespaceValidator

Source

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”)
Source

pub fn aws_iot() -> Self

Creates a validator configured for AWS IoT Core

Source

pub fn azure_iot() -> Self

Creates a validator configured for Azure IoT Hub

Source

pub fn google_cloud_iot() -> Self

Creates a validator configured for Google Cloud IoT

Source

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}/*

Source

pub fn with_system_topics(self, allow: bool) -> Self

Enables system topics ($SYS/*)

Source

pub fn with_reserved_prefix(self, prefix: impl Into<String>) -> Self

Adds an additional reserved prefix

Trait Implementations§

Source§

impl Clone for NamespaceValidator

Source§

fn clone(&self) -> NamespaceValidator

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NamespaceValidator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl TopicValidator for NamespaceValidator

Source§

fn validate_topic_name(&self, topic: &str) -> Result<()>

Validates a topic name for publishing Read more
Source§

fn validate_topic_filter(&self, filter: &str) -> Result<()>

Validates a topic filter for subscriptions Read more
Source§

fn is_reserved_topic(&self, topic: &str) -> bool

Checks if a topic is reserved and should be restricted Read more
Source§

fn description(&self) -> &'static str

Gets a human-readable description of the validator

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more