Skip to main content

grafeo_core/graph/
mod.rs

1//! Graph model implementations.
2//!
3//! Pick your graph model:
4//!
5//! | Model | When to use | Example use case |
6//! | ----- | ----------- | ---------------- |
7//! | [`lpg`] | Most apps (default) | Social networks, fraud detection |
8//! | [`compact`] | Read-heavy / embedded (feature-gated: `compact-store`) | WASM, edge workers, static snapshots |
9//! | [`rdf`] | Knowledge graphs | Ontologies, linked data (feature-gated) |
10//!
11//! These are separate implementations with no abstraction overhead - you get
12//! the full performance of whichever model you choose.
13
14pub mod lpg;
15pub mod traits;
16
17#[cfg(feature = "compact-store")]
18pub mod compact;
19
20#[cfg(feature = "triple-store")]
21pub mod rdf;
22
23pub use traits::{GraphStore, GraphStoreMut, NullGraphStore};
24
25/// Controls which edges to follow during traversal.
26///
27/// Most graph operations need to specify direction. Use [`Outgoing`](Self::Outgoing)
28/// when you care about relationships *from* a node, [`Incoming`](Self::Incoming) for
29/// relationships *to* a node, and [`Both`](Self::Both) when direction doesn't matter.
30#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
31#[non_exhaustive]
32pub enum Direction {
33    /// Follow outgoing edges (A)-\[r\]->(B) from A's perspective.
34    Outgoing,
35    /// Follow incoming edges (A)<-\[r\]-(B) from A's perspective.
36    Incoming,
37    /// Follow edges in either direction - treat the graph as undirected.
38    Both,
39}
40
41impl Direction {
42    /// Flips the direction - outgoing becomes incoming and vice versa.
43    ///
44    /// Useful when traversing backward along a path.
45    #[must_use]
46    pub const fn reverse(self) -> Self {
47        match self {
48            Direction::Outgoing => Direction::Incoming,
49            Direction::Incoming => Direction::Outgoing,
50            Direction::Both => Direction::Both,
51        }
52    }
53}