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//! | [`rdf`] | Knowledge graphs | Ontologies, linked data (feature-gated) |
9//!
10//! These are separate implementations with no abstraction overhead - you get
11//! the full performance of whichever model you choose.
12
13pub mod lpg;
14
15#[cfg(feature = "rdf")]
16pub mod rdf;
17
18/// Controls which edges to follow during traversal.
19///
20/// Most graph operations need to specify direction. Use [`Outgoing`](Self::Outgoing)
21/// when you care about relationships *from* a node, [`Incoming`](Self::Incoming) for
22/// relationships *to* a node, and [`Both`](Self::Both) when direction doesn't matter.
23#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
24pub enum Direction {
25    /// Follow outgoing edges (A)-\[r\]->(B) from A's perspective.
26    Outgoing,
27    /// Follow incoming edges (A)<-\[r\]-(B) from A's perspective.
28    Incoming,
29    /// Follow edges in either direction - treat the graph as undirected.
30    Both,
31}
32
33impl Direction {
34    /// Flips the direction - outgoing becomes incoming and vice versa.
35    ///
36    /// Useful when traversing backward along a path.
37    #[must_use]
38    pub const fn reverse(self) -> Self {
39        match self {
40            Direction::Outgoing => Direction::Incoming,
41            Direction::Incoming => Direction::Outgoing,
42            Direction::Both => Direction::Both,
43        }
44    }
45}