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