use crate::{DaemonicEmission, DaemonicError, Glass};
use alloc::string::String;
use daemonic_error::daemonic::{SemanticAnchor, SpatialAnchor, SymbolicAnchor};
use crate::{Annotation, GlassEcho, ObservationTier, Severity, Temporal, TopologySegment};
use super::super::super::glass_flags::GlassFlags;
#[derive(Clone, Debug)]
pub struct Echo<GLASS> {
position: &'static TopologySegment,
severity: Severity,
tier: ObservationTier,
annotation: Annotation,
temporal: Temporal,
payload: Option<GLASS>,
flags: GlassFlags,
}
impl<GLASS> Echo<GLASS> {
pub fn new(payload: Option<GLASS>, position: &'static TopologySegment) -> Self {
Echo {
position,
severity: Severity::Echo,
tier: ObservationTier::Composed,
annotation: Annotation::None,
temporal: Temporal::Current,
payload,
flags: GlassFlags::echo_defaults(),
}
}
pub fn extract_flags(&self) -> GlassFlags { self.flags }
pub fn mutate_temporal(&mut self, temporal: Temporal) {
self.temporal = temporal;
}
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
}
pub fn extract_severity(&self) -> Severity {
self.severity
}
pub fn mutate_annotation(&mut self, a: Annotation) {
self.annotation = a;
}
pub fn query_payload(&self) -> Option<&GLASS> {
if self.payload.is_some() {
Some(self.payload.as_ref().unwrap())
} else {
None
}
}
pub fn extract_referent_payload(&self) -> Option<&GLASS> {
self.payload.as_ref()
}
pub fn extract_owned_payload(self) -> Option<GLASS> {
self.payload
}
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 ECHO_TOPOLOGY: ::daemonic_error::daemonic::TopologySegment =
::daemonic_error::daemonic::TopologySegment::new("Daemonic::Glass::States::Echo<GLASS>");
impl<GLASS> ::daemonic_error::daemonic::Anchor for Echo<GLASS> {
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<GLASS> SymbolicAnchor for Echo<GLASS> {
type Anchor = ::daemonic_error::daemonic::TopologySegment;
fn meaningful_within(&self) -> Self::Anchor {
ECHO_TOPOLOGY.clone()
}
}
impl<GLASS> SemanticAnchor for Echo<GLASS> {}
impl<GLASS> SpatialAnchor for Echo<GLASS> {
fn anchor_position(&self) -> &::daemonic_error::daemonic::TopologySegment {
&ECHO_TOPOLOGY
}
fn neighbors(&self) -> ::daemonic_error::daemonic::TopologySegment {
ECHO_TOPOLOGY.clone()
}
}
impl<GLASS> ::daemonic_error::daemonic::StructuralAnchor for Echo<GLASS> {
fn contract_description(&self) -> &str {
"Echo: auto-derived Daemonic anchor via #[daemonic] proc macro"
}
}
impl<GLASS> ::daemonic_error::TopologyAnchor for Echo<GLASS> {
fn parent(&self) -> Option<::daemonic_error::daemonic::TopologySegment> {
let label = ECHO_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 {
&ECHO_TOPOLOGY
}
fn depth(&self) -> usize {
ECHO_TOPOLOGY.depth as usize
}
}
impl<GLASS: Glass<GLASS> + Glass<Echo<GLASS>>> GlassEcho<GLASS> for Echo<GLASS>
where
GLASS: for<'error> DaemonicError<'error>,
{
fn original_tick(&self) -> u64 {
todo!()
}
fn staleness(&self) -> u64 {
todo!()
}
}
impl<GLASS> DaemonicError<'_> for Echo<GLASS>
where
GLASS: for<'error> DaemonicError<'error>,
{
fn emit(self) -> DaemonicEmission {
todo!()
}
fn position(&self) -> &TopologySegment {
todo!()
}
}
impl<GLASS: Glass<GLASS> + Glass<Echo<GLASS>>> Glass<GLASS> for Echo<GLASS> {
type Anchor = TopologySegment;
fn position(&self) -> &TopologySegment {
self.extract_position()
}
fn severity(&self) -> Severity {
self.extract_severity()
}
fn payload(&self) -> Option<&GLASS> {
self.extract_referent_payload()
}
fn into_payload(self) -> Option<GLASS>
where
Self: Sized,
GLASS: Sized,
{
self.extract_owned_payload()
}
}