use slotmap::new_key_type;
new_key_type! {
/// Element 句柄
pub struct ElementId;
/// RenderObject 句柄
pub struct RenderObjectId;
/// Layer 句柄
pub struct LayerId;
}
impl ElementId {
/// 无障碍树的合成根节点 id(不属于任何 Element)。
///
/// AccessKit 要求单根,而主树与各 overlay 是平行森林,因此 core 在
/// `build_accessibility_tree` 里插入这个稳定 id 作为容器根。
/// 选 `u64::MAX`:slotmap 的实际分配永远达不到该索引,不会与真实 Element 冲突。
pub const A11Y_ROOT: Self = Self(slotmap::KeyData::from_ffi(u64::MAX));
/// 从 FFI u64 构造(供 runtime 测试 + accesskit NodeId 桥接)
pub fn from_ffi(data: u64) -> Self {
// slotmap 1.1 的 new_key_type 生成 tuple struct,KeyData::from_ffi 可用
#[allow(clippy::let_and_return)]
Self(slotmap::KeyData::from_ffi(data))
}
/// 导出为 FFI u64(和 NodeId 互转)
pub fn to_ffi(self) -> u64 {
<Self as slotmap::Key>::data(&self).as_ffi()
}
}