Skip to main content

arc_graph_core/
ids.rs

1//! 稳定 ID:序列化与筛选回放依赖 ID 不随存储位置变化。与 arc-flow-core 的
2//! `NodeId` / `EdgeId` 数值不互通(两套图是不同领域),前缀区分便于日志排障。
3
4use serde::{Deserialize, Serialize};
5use std::fmt;
6
7macro_rules! id_type {
8    ($name:ident, $prefix:literal) => {
9        #[derive(
10            Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize,
11        )]
12        #[serde(transparent)]
13        pub struct $name(pub u64);
14
15        impl $name {
16            /// 原始数值(序列化 / CSV 列使用)。
17            pub fn raw(self) -> u64 {
18                self.0
19            }
20        }
21
22        impl fmt::Display for $name {
23            fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24                write!(f, concat!($prefix, "{}"), self.0)
25            }
26        }
27    };
28}
29
30id_type!(NodeId, "kn");
31id_type!(EdgeId, "ke");
32id_type!(KindId, "kt");