Skip to main content

cognee_models/
has_datapoint.rs

1//! The `HasDataPoint` trait used by the provenance-stamping algorithm
2//! in `cognee-core::provenance`.
3//!
4//! This trait lives in `cognee-models` (next to its primary impls) and
5//! is re-exported from `cognee_core::provenance` so the public path
6//! `cognee_core::provenance::HasDataPoint` keeps resolving for
7//! downstream consumers. Placement decision recorded in
8//! `docs/telemetry/05/04-has-datapoint-impls.md` ยง4.1.
9
10use crate::DataPoint;
11
12/// Read / write access to the embedded `DataPoint` of a typed container,
13/// plus a hook to recurse into nested `DataPoint`-bearing children.
14///
15/// This trait is the Rust analogue of Python's reflective
16/// `model_fields` walk. Implementations are added crate-by-crate
17/// (typically here in `cognee-models`); types not implementing the
18/// trait are silently passed through by `cognee_core::provenance::stamp_tree`.
19pub trait HasDataPoint {
20    /// Borrow the embedded `DataPoint` of this container.
21    fn data_point(&self) -> &DataPoint;
22
23    /// Mutably borrow the embedded `DataPoint` of this container.
24    fn data_point_mut(&mut self) -> &mut DataPoint;
25
26    /// Visit every owned child that itself implements `HasDataPoint`.
27    /// Default: no children. Override on container types whose fields
28    /// own (rather than reference by `Uuid`) another `HasDataPoint`.
29    fn for_each_child_mut(&mut self, _visit: &mut dyn FnMut(&mut dyn HasDataPoint)) {}
30}