daemonic_error 1.0.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 alloc::borrow::ToOwned;
use alloc::string::ToString;
use alloc::vec::Vec;
use ::daemonic_error::daemonic::observation::Cracked;
use super::{Glass, GlassStable};
use crate::daemonic::glass::Severity;
use crate::{Annotation, DaemonicError, ObservationTier, Temporal, TopologySegment};

/// Damaged but contained. Non-propagating.
/// The crack exists but isn't spreading.
/// Key property: can_cascade returns false.
pub trait GlassCracked<GLASS>: Glass<GLASS> + for<'error> DaemonicError<'error> {
	/// Is the crack stable or growing?
	fn is_holding(&self) -> bool;
	
	/// Attempt containment. Returns whether crack was stabilized.
	fn contain(&mut self) -> bool {
		// Default: already contained, return current holding state
		self.is_holding()
	}
	
	/// Optional repair closure.
	/// If provided, attempt repair. Costs a clock tick (work).
	/// Returns improved glass on success.
	fn repair(&self) -> Option<&dyn Fn() -> GLASS> {
		None
	}
	fn annotate(&self) -> Annotation { Annotation::None }
}
/// Type erased implementation for frame transformation theory logic
impl<GLASS: Glass<GLASS> + Clone> dyn GlassCracked<GLASS, Anchor=TopologySegment> {
	fn self_reconstruct<G: for<'error> DaemonicError<'error> + GlassCracked<GLASS>>(self, p: G, top: &TopologySegment) -> ::daemonic_error::daemonic::observation::Cracked<G>
		where
			Self: Sized,
	{
		todo!()
		// ::daemonic_error::daemonic::observation::Cracked::new(Some(p), top)
	}
	/// This function should only be really useful inside a dyn namespace where nothing is available except the trait
	fn erase_and_reconstruct(payload: Option<GLASS>, top: &'static TopologySegment) -> ::daemonic_error::daemonic::observation::Cracked<GLASS> {
		let mut cracked = ::daemonic_error::daemonic::observation::Cracked::new(payload.to_owned(), top);
		if payload.is_none() {
			cracked = cracked.with_note(
				"Payload did not survive transition or None is intended"
			);
		}
		cracked
	}
}