daemonic_error 0.1.0

Errors that compose, predict, and leave receipts - Compose: algebraic combination (in active development) - Predict: Glass/Severity - Receipts: audit trail, position, checksum - Reflection: Runtime Reflection through TopologySegment (in active development)
use crate::daemonic::{Anchor, StructuralAnchor};
use crate::daemonic::glass::Glass;
use crate::daemonic::glass::states::GlassStable;

/// Fixes a position in the lattice.
/// DB mapping: D7 (Semantic Weight) + D8 (Causal Reach)
///
/// Position implements this. Lattice nodes implement this.
/// Every Glass observation has a position that is a SpatialAnchor.
pub trait SpatialAnchor: Anchor {
	/// The fixed position this anchor represents.
	fn anchor_position(&self) -> &TopologySegment;

	/// Distance from this anchor to another position.
	/// Returns None if no path exists (different root categories).
	fn distance_to(&self, other: &TopologySegment) -> Option<usize> {
		// Default: compute from position segments
		let self_pos = self.anchor_position();
		let common = self_pos.segments().payload()
			.iter()
			.zip(other.segments().payload().iter())
			.take_while(|(a, b)| a == b)
			.count();
		if common == 0 { return None; }
		let up = self_pos.depth() - common;
		let down = other.depth() - common;
		Some(up + down)
	}

	/// Immediate neighbors in the lattice.
	/// Default: empty (override for types with topology knowledge).
	fn neighbors(&self) -> TopologySegment;
}
pub use topology::{TopologySegment, TopologyAnchor, GLASS_SEG, DAEMONIC_SEG};

pub mod topology;