1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
use std::num::NonZeroU32;
use std::u32;

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct NodeIndex {
    index: NonZeroU32,
}

impl NodeIndex {
    #[inline]
    pub fn new(value: usize) -> NodeIndex {
        assert!(value < (u32::MAX as usize));
        NodeIndex { index: NonZeroU32::new((value as u32) + 1).unwrap() }
    }

    #[inline]
    pub fn get(self) -> usize {
        (self.index.get() - 1) as usize
    }
}