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::String;
use core::hint::unreachable_unchecked;
use super::{Glass, Paradox};
use crate::{Annotation, DaemonicEmission, DaemonicError, ObservationTier, Severity, Temporal, TopologySegment};
use super::super::super::glass_flags::GlassFlags;
#[derive(Clone, Debug)]
pub struct Shattered {
	position: &'static TopologySegment,
	severity: Severity,
	tier: ObservationTier,
	annotation: Annotation,
	temporal: Temporal,
	flags: GlassFlags,
}
impl Shattered {
	pub fn new(position: &'static TopologySegment) -> Self {
		Shattered {
			position,
			severity: Severity::Shattered,
			tier: ObservationTier::Absolute,
			annotation: Annotation::None,
			temporal: Temporal::Current,
			flags: GlassFlags::terminal(),
		}
	}
	pub fn extract_flags(&self) -> GlassFlags { self.flags }
	// pub fn mutate_tier(&mut self, tier: ObservationTier) -> Self {
	// 	Self {
	// 		position: &self.position,
	// 		severity: self.severity,
	// 		tier,
	// 		annotation: self.annotation,
	// 		temporal: self.temporal,
	// 		flags: GlassFlags::terminal(),
	// 	}
	// }
	pub fn extract_position(&self) -> &'static TopologySegment {
		self.position
	}
	pub fn extract_position_label(&self) -> &str {
		self.position.label
	}
	pub fn extract_tier(&self) -> ObservationTier {
		self.tier
	}
	pub fn extract_annotation(&self) -> Annotation {
		self.annotation.clone()
	}
	pub fn extract_temporal(&self) -> Temporal {
		self.temporal
	}
	/// This method seems redundant, but theres a reason for its existence, States declare their own severity
	/// as well as the label. One reason is due to a ton of shit already using severity, but also
	/// explicitness.
	/// The old Observation State struct had public fields and was generic by design, States should
	/// be equated with Severity.
	/// IE Severity == State == Severity
	/// So as an additional safety precaution, the new structures are no longer field public, constructors
	/// extract data and pass to the consumer. Call site declarations should reflect this.
	/// Use extractor functions, dont exfil field data.
	pub fn extract_severity(&self) -> Severity {
		self.severity
	}
	// pub fn with_note(&mut self, note: impl Into<String>) -> Self {
	// 	Shattered {
	// 		position: &Self::extract_position(&self),
	// 		severity: Severity::Shattered,
	// 		tier: Self::extract_tier(&self),
	// 		annotation: Annotation::Note(note.into()),
	// 		temporal: Temporal::Current,
	// 		flags: GlassFlags::terminal(),
	// 	}
	// }
	// pub fn with_suggestion(&mut self, suggestion: impl Into<String>) -> Self {
	// 	Shattered {
	// 		position: &Self::extract_position(&self),
	// 		severity: Severity::Shattered,
	// 		tier: Self::extract_tier(&self),
	// 		annotation: Annotation::Suggestion(suggestion.into()),
	// 		temporal: Temporal::Current,
	// 		flags: GlassFlags::terminal(),
	// 	}
	// }
	// pub fn with_help(&mut self, help: impl Into<String>) -> Self {
	// 	Shattered {
	// 		position: &Self::extract_position(&self),
	// 		severity: Severity::Shattered,
	// 		tier: Self::extract_tier(&self),
	// 		annotation: Annotation::Help(help.into()),
	// 		temporal: Temporal::Current,
	// 		flags: GlassFlags::terminal(),
	// 	}
	// }
	pub fn mutate_annotation(&mut self, a: Annotation) {
		self.annotation = a;
	}
	pub fn with_note(mut self, note: impl Into<String>) -> Self {
		self.annotation = Annotation::Note(note.into());
		self
	}
	pub fn with_suggestion(mut self, suggestion: impl Into<String>) -> Self {
		self.annotation = Annotation::Suggestion(suggestion.into());
		self
	}
	pub fn with_help(mut self, help: impl Into<String>) -> Self {
		self.annotation = Annotation::Suggestion(help.into());
		self
	}
	pub fn mutate_tier(mut self, tier: impl Into<ObservationTier>) -> Self {
		self.tier = tier.into();
		self
	}
}
pub const SHATTERED_TOPOLOGY: ::daemonic_error::daemonic::TopologySegment = ::daemonic_error::daemonic::TopologySegment::new("Daemonic::Glass::States::Shattered");
impl ::daemonic_error::daemonic::Anchor for Shattered {
	fn anchor_domains(&self) -> ::daemonic_error::daemonic::AnchorDomainSet {
		::daemonic_error::daemonic::AnchorDomainSet::SPATIAL
			.union(::daemonic_error::daemonic::AnchorDomainSet::STRUCTURAL)
			.union(::daemonic_error::daemonic::AnchorDomainSet::SYMBOLIC)
	}
}
impl ::daemonic_error::daemonic::SymbolicAnchor for Shattered {
	type Anchor = ::daemonic_error::daemonic::TopologySegment;
	fn meaningful_within(&self) -> Self::Anchor {
		SHATTERED_TOPOLOGY.clone()
	}
}
impl ::daemonic_error::daemonic::SemanticAnchor for Shattered {}
impl ::daemonic_error::daemonic::SpatialAnchor for Shattered {
	fn anchor_position(&self) -> &::daemonic_error::daemonic::TopologySegment {
		&SHATTERED_TOPOLOGY
	}
	fn neighbors(&self) -> ::daemonic_error::daemonic::TopologySegment {
		SHATTERED_TOPOLOGY.clone()
	}
}
impl ::daemonic_error::daemonic::StructuralAnchor for Shattered {
	fn contract_description(&self) -> &str {
		"Shattered: auto-derived Daemonic anchor via #[daemonic] proc macro"
	}
}
impl ::daemonic_error::TopologyAnchor for Shattered {
	fn parent(&self) -> Option<::daemonic_error::daemonic::TopologySegment> {
		let label = SHATTERED_TOPOLOGY.label;
		label.rsplit_once("::").map(|(parent, _)| {
			<::daemonic_error::TopologySegment as ::daemonic_error::TopologyAnchor>::new_anchor(
				parent,
			)
		})
	}
	fn children(&self) -> &[::daemonic_error::daemonic::TopologySegment] {
		&[]
	}
	fn segments(&self) -> &::daemonic_error::daemonic::TopologySegment {
		&SHATTERED_TOPOLOGY
	}
	fn depth(&self) -> usize {
		SHATTERED_TOPOLOGY.depth as usize
	}
}

impl ::daemonic_error::daemonic::glass::states::GlassShattered<!> for Shattered {}
impl Glass<!> for ! {
	type Anchor = TopologySegment;
	
	fn position(&self) -> &TopologySegment {
		unsafe { unreachable_unchecked() }
	}
	
	fn severity(&self) -> Severity {
		unsafe { unreachable_unchecked() }
	}
	
	fn payload(&self) -> Option<&!> {
		unsafe { unreachable_unchecked() }
	}
	
	fn into_payload(self) -> Option<!>
		where
			Self: Sized,
			!: Sized,
	{
		unsafe { unreachable_unchecked() }
	}
}
impl Glass<!> for Shattered {
	type Anchor = TopologySegment;
	
	fn position(&self) -> &TopologySegment {
		unsafe { unreachable_unchecked() }
	}
	
	fn severity(&self) -> Severity {
		unsafe { unreachable_unchecked() }
	}
	
	fn payload(&self) -> Option<&!> {
		unsafe { unreachable_unchecked() }
	}
	
	fn into_payload(self) -> Option<!>
		where
			Self: Sized,
			!: Sized,
	{
		unsafe { unreachable_unchecked() }
	}
}
impl Glass<Shattered> for Shattered {
	type Anchor = TopologySegment;
	
	fn position(&self) -> &TopologySegment {
		self.extract_position()
	}
	
	fn severity(&self) -> Severity {
		self.extract_severity()
	}
	/// In the context of a Shattered Glass object, Self (the struct itself) is the payload
	fn payload(&self) -> Option<&Shattered> {
		Some(self)
	}
	/// In the context of a Shattered Glass object, Self (the struct itself) is the payload
	fn into_payload(self) -> Option<Shattered>
		where
			Self: Sized,
			Shattered: Sized,
	{
		Some(self)
	}
}
impl DaemonicError<'_> for Shattered {
	fn emit(self) -> DaemonicEmission {
		todo!()
	}
	
	fn position(&self) -> &TopologySegment {
		self.extract_position()
	}
}