traitgraph::index

Trait OptionalGraphIndex

Source
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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

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

Source§

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