Skip to main content

TopicProvider

Trait TopicProvider 

Source
pub trait TopicProvider<T>: Send + Sync {
    // Required method
    fn topic(&self, value: &T) -> Option<String>;
}
Expand description

Trait for dynamic topic providers (outbound only)

Implement this trait to dynamically determine MQTT topics (or KNX group addresses) based on the data being published. This enables reusable routing logic that can be shared across multiple record types.

§Type Safety

The trait is generic over T, providing compile-time type safety at the implementation site. Type erasure occurs only at storage time.

§no_std Compatibility

Works in both std and no_std + alloc environments.

§Example

use aimdb_core::connector::TopicProvider;

struct SensorTopicProvider;

impl TopicProvider<Temperature> for SensorTopicProvider {
    fn topic(&self, value: &Temperature) -> Option<String> {
        Some(format!("sensors/temp/{}", value.sensor_id))
    }
}

Required Methods§

Source

fn topic(&self, value: &T) -> Option<String>

Determine the topic/destination for a given value

Returns Some(topic) to use a dynamic topic, or None to fall back to the static topic from the link_to() URL.

Implementors§