pub trait OptionalGraphIndex<MirrorGraphIndex: GraphIndex<Self>>: Default + Debug + Eq + Ord + Hash + Copy + Sized + From<usize> + From<Option<usize>> + From<MirrorGraphIndex> + From<Option<MirrorGraphIndex>> + Into<Option<MirrorGraphIndex>> + Add<usize, Output = Self> + Sub<usize, Output = Self> {
    // Required methods
    fn as_usize(self) -> Option<usize>;
    fn as_usize_unchecked(self) -> usize;

    // Provided methods
    fn is_valid(self) -> bool { ... }
    fn is_none(self) -> bool { ... }
    fn is_some(self) -> bool { ... }
    fn new_none() -> Self { ... }
    fn unwrap(self) -> MirrorGraphIndex { ... }
}
Expand description

A graph index that can be None. This is a hack to get a small sized Option<GraphIndex> by storing the None variant as IndexType::max_value(). If Rust ever adds support for integer types with invalid values other than 0, this trait becomes obsolete.

Required Methods§

source

fn as_usize(self) -> Option<usize>

Get this index as usize, but return None if this index is marked as invalid.

source

fn as_usize_unchecked(self) -> usize

A faster method to get the usize value of the index, which does not perform any validity checks.

Provided Methods§

source

fn is_valid(self) -> bool

Returns true if the index is valid, i.e. if it is not marked as invalid.

source

fn is_none(self) -> bool

Returns true if the index is None.

source

fn is_some(self) -> bool

Returns true if the index is Some.

source

fn new_none() -> Self

Returns a new OptionalGraphIndex that is marked as invalid.

source

fn unwrap(self) -> MirrorGraphIndex

Returns the graph index stored in this optional graph index. Panics if this optional graph index is None.

Implementors§

source§

impl<IndexType: PrimInt + Hash> OptionalGraphIndex<EdgeIndex<IndexType>> for OptionalEdgeIndex<IndexType>

source§

impl<IndexType: PrimInt + Hash> OptionalGraphIndex<NodeIndex<IndexType>> for OptionalNodeIndex<IndexType>