Skip to main content

arc_flow_core/
ids.rs

1//! 稳定 ID:序列化、撤销回放与多人协作都依赖 ID 不随存储位置变化。
2
3use serde::{Deserialize, Serialize};
4use std::fmt;
5
6macro_rules! id_type {
7    ($name:ident, $prefix:literal) => {
8        #[derive(
9            Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize,
10        )]
11        #[serde(transparent)]
12        pub struct $name(pub u64);
13
14        impl fmt::Display for $name {
15            fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16                write!(f, concat!($prefix, "{}"), self.0)
17            }
18        }
19    };
20}
21
22id_type!(NodeId, "n");
23id_type!(PortId, "p");
24id_type!(EdgeId, "e");