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;
14pub mod traits;
15
16#[cfg(feature = "rdf")]
17pub mod rdf;
18
19pub use traits::{GraphStore, GraphStoreMut};
20
21/// Controls which edges to follow during traversal.
22///
23/// Most graph operations need to specify direction. Use [`Outgoing`](Self::Outgoing)
24/// when you care about relationships *from* a node, [`Incoming`](Self::Incoming) for
25/// relationships *to* a node, and [`Both`](Self::Both) when direction doesn't matter.
26#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
27pub enum Direction {
28    /// Follow outgoing edges (A)-\[r\]->(B) from A's perspective.
29    Outgoing,
30    /// Follow incoming edges (A)<-\[r\]-(B) from A's perspective.
31    Incoming,
32    /// Follow edges in either direction - treat the graph as undirected.
33    Both,
34}
35
36impl Direction {
37    /// Flips the direction - outgoing becomes incoming and vice versa.
38    ///
39    /// Useful when traversing backward along a path.
40    #[must_use]
41    pub const fn reverse(self) -> Self {
42        match self {
43            Direction::Outgoing => Direction::Incoming,
44            Direction::Incoming => Direction::Outgoing,
45            Direction::Both => Direction::Both,
46        }
47    }
48}