pub type NodeId = slotmap::DefaultKey;
#[inline]
pub fn node_id_to_ffi(id: NodeId) -> u64 {
use slotmap::Key;
id.data().as_ffi()
}
#[inline]
pub fn node_id_from_ffi(ffi: u64) -> NodeId {
slotmap::KeyData::from_ffi(ffi).into()
}
#[cfg(test)]
mod tests {
use super::*;
use slotmap::SlotMap;
#[test]
fn round_trip_through_ffi() {
let mut sm = SlotMap::new();
let id: NodeId = sm.insert("hello");
let encoded = node_id_to_ffi(id);
let decoded = node_id_from_ffi(encoded);
assert_eq!(id, decoded);
assert_eq!(sm[decoded], "hello");
}
#[test]
fn bogus_ffi_value_does_not_crash() {
let sm: SlotMap<NodeId, ()> = SlotMap::new();
let bogus = node_id_from_ffi(0xDEAD_BEEF);
assert!(sm.get(bogus).is_none());
}
}