1#[cfg(feature = "taffy_tree")]
6use slotmap::{DefaultKey, Key, KeyData};
7
8#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
13pub struct NodeId(u64);
14impl NodeId {
15 pub const fn new(val: u64) -> Self {
17 Self(val)
18 }
19}
20
21impl From<u64> for NodeId {
22 #[inline]
23 fn from(raw: u64) -> Self {
24 Self(raw)
25 }
26}
27impl From<NodeId> for u64 {
28 #[inline]
29 fn from(id: NodeId) -> Self {
30 id.0
31 }
32}
33impl From<usize> for NodeId {
34 #[inline]
35 fn from(raw: usize) -> Self {
36 Self(raw as u64)
37 }
38}
39impl From<NodeId> for usize {
40 #[inline]
41 fn from(id: NodeId) -> Self {
42 id.0 as usize
43 }
44}
45
46#[cfg(feature = "taffy_tree")]
47impl From<DefaultKey> for NodeId {
48 #[inline]
49 fn from(key: DefaultKey) -> Self {
50 Self(key.data().as_ffi())
51 }
52}
53
54#[cfg(feature = "taffy_tree")]
55impl From<NodeId> for DefaultKey {
56 #[inline]
57 fn from(key: NodeId) -> Self {
58 KeyData::from_ffi(key.0).into()
59 }
60}