Skip to main content

qubit_event_bus/core/
topic_key.rs

1/*******************************************************************************
2 *
3 *    Copyright (c) 2026 Haixing Hu.
4 *
5 *    SPDX-License-Identifier: Apache-2.0
6 *
7 *    Licensed under the Apache License, Version 2.0.
8 *
9 ******************************************************************************/
10//! Type-erased topic key.
11
12use std::any::TypeId;
13
14/// Hashable key used internally to separate topics by name and payload type.
15#[derive(Debug, Clone, Eq, PartialEq, Hash)]
16pub struct TopicKey {
17    pub(crate) name: String,
18    pub(crate) payload_type_id: TypeId,
19}
20
21impl TopicKey {
22    /// Creates a topic key.
23    ///
24    /// # Parameters
25    /// - `name`: Topic name.
26    /// - `payload_type_id`: Rust [`TypeId`] of the payload.
27    ///
28    /// # Returns
29    /// A new key suitable for hash maps.
30    pub(crate) fn new(name: String, payload_type_id: TypeId) -> Self {
31        Self {
32            name,
33            payload_type_id,
34        }
35    }
36}