pub trait GraphStore {
// Required methods
fn relate(
&self,
from: u64,
to: u64,
relation: &str,
) -> Result<u64, MemoryError>;
fn relations(&self, id: u64) -> Result<Vec<MemoryEdge>, MemoryError>;
fn incoming_relations(
&self,
id: u64,
) -> Result<Vec<MemoryEdge>, MemoryError>;
fn relations_bounded(
&self,
id: u64,
cap: usize,
) -> Result<BoundedMemoryEdges, MemoryError>;
fn incoming_relations_bounded(
&self,
id: u64,
cap: usize,
) -> Result<BoundedMemoryEdges, MemoryError>;
fn unrelate(&self, edge_id: u64) -> Result<bool, MemoryError>;
// Provided methods
fn unrelate_from(
&self,
from: u64,
edge_id: u64,
) -> Result<bool, MemoryError> { ... }
fn edge_count(&self) -> Option<usize> { ... }
}Expand description
Typed graph edges between facts — the facet behind relate/why and
the hub walks. A backend without a graph simply does not implement it,
and the service methods that need it stop existing for that backend at
compile time.
Required Methods§
Sourcefn relate(&self, from: u64, to: u64, relation: &str) -> Result<u64, MemoryError>
fn relate(&self, from: u64, to: u64, relation: &str) -> Result<u64, MemoryError>
Create a typed edge from -> to. Returns the edge id.
§Errors
Returns MemoryError if either endpoint is missing or persistence fails.
Sourcefn relations(&self, id: u64) -> Result<Vec<MemoryEdge>, MemoryError>
fn relations(&self, id: u64) -> Result<Vec<MemoryEdge>, MemoryError>
Sourcefn incoming_relations(&self, id: u64) -> Result<Vec<MemoryEdge>, MemoryError>
fn incoming_relations(&self, id: u64) -> Result<Vec<MemoryEdge>, MemoryError>
The incoming edges of id — the mirror of Self::relations, with
the same liveness rule applied to the far end (here the source).
§Errors
Returns MemoryError if storage access fails.
Sourcefn relations_bounded(
&self,
id: u64,
cap: usize,
) -> Result<BoundedMemoryEdges, MemoryError>
fn relations_bounded( &self, id: u64, cap: usize, ) -> Result<BoundedMemoryEdges, MemoryError>
At most cap outgoing edges of id, plus whether its total degree
exceeded the scan — the bounded twin of Self::relations (#1820).
The contract is on COST, not just shape: an implementation must keep
work and transient allocation O(cap), never O(degree) — a super-node
(an entity hub mentioned by thousands of facts) is exactly where this
accessor is reached for. truncated is a separate signal because
edges.len() == cap cannot carry it: a node with exactly cap edges
is indistinguishable from a truncated one.
§Errors
Returns MemoryError if storage access fails.
Sourcefn incoming_relations_bounded(
&self,
id: u64,
cap: usize,
) -> Result<BoundedMemoryEdges, MemoryError>
fn incoming_relations_bounded( &self, id: u64, cap: usize, ) -> Result<BoundedMemoryEdges, MemoryError>
At most cap incoming edges of id, plus whether its total incoming
degree exceeded the scan — the mirror of Self::relations_bounded,
same O(cap) cost contract.
§Errors
Returns MemoryError if storage access fails.
Sourcefn unrelate(&self, edge_id: u64) -> Result<bool, MemoryError>
fn unrelate(&self, edge_id: u64) -> Result<bool, MemoryError>
Remove the edge with edge_id. Returns true when it existed —
idempotent: removing an absent edge is Ok(false), never an error.
§Errors
Returns MemoryError if storage access fails.
Provided Methods§
Sourcefn unrelate_from(&self, from: u64, edge_id: u64) -> Result<bool, MemoryError>
fn unrelate_from(&self, from: u64, edge_id: u64) -> Result<bool, MemoryError>
Remove an edge while preserving its known source for mutation capture.
The default keeps third-party backends source-compatible. Native
online migration overrides it so OutgoingEdges(from) is recorded
before the edge is removed.
§Errors
Returns MemoryError if storage access fails.
Sourcefn edge_count(&self) -> Option<usize>
fn edge_count(&self) -> Option<usize>
The total number of graph edges, when the backend can answer without
materializing them — the observable difference between a store whose
why() can walk somewhere and one where it degrades to plain
similarity search.
Defaulted to None (“cannot say”) rather than required, deliberately:
a backend outside this crate (velesdb-wasm’s in-memory store) must
keep compiling when this surface grows, and a wrong-but-cheap answer
here would flag healthy graphs as flat. memory_status reports the
distinction to the caller instead of papering over it.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl GraphStore for NativeStore
persistence only.