uni_store/storage/direction.rs
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2024-2026 Dragonscale Team
3
4//! Graph edge traversal direction.
5
6/// Edge traversal direction for adjacency lookups.
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8pub enum Direction {
9 /// Outgoing (forward) edges from a vertex.
10 Outgoing,
11 /// Incoming (backward) edges to a vertex.
12 Incoming,
13 /// Both outgoing and incoming edges.
14 Both,
15}
16
17impl Direction {
18 /// Returns the short string representation used in storage keys.
19 pub fn as_str(&self) -> &'static str {
20 match self {
21 Direction::Outgoing => "fwd",
22 Direction::Incoming => "bwd",
23 Direction::Both => "both",
24 }
25 }
26
27 /// Expands `Both` into `[Outgoing, Incoming]`; otherwise returns a
28 /// single-element slice containing the direction itself.
29 pub fn expand(&self) -> &'static [Direction] {
30 match self {
31 Direction::Both => &[Direction::Outgoing, Direction::Incoming],
32 Direction::Outgoing => &[Direction::Outgoing],
33 Direction::Incoming => &[Direction::Incoming],
34 }
35 }
36}